From dffbca432e017704229b3e4dd582664a07003693 Mon Sep 17 00:00:00 2001 From: LepilkinaElena Date: Thu, 4 Jun 2020 13:55:54 +0400 Subject: [PATCH] Benchmark for objects allocations (#4216) --- performance/ring/src/main/kotlin/main.kt | 1 + .../org/jetbrains/ring/AllocationBenchmark.kt | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 performance/ring/src/main/kotlin/org/jetbrains/ring/AllocationBenchmark.kt diff --git a/performance/ring/src/main/kotlin/main.kt b/performance/ring/src/main/kotlin/main.kt index 2ae574ff344..475318c6a05 100644 --- a/performance/ring/src/main/kotlin/main.kt +++ b/performance/ring/src/main/kotlin/main.kt @@ -26,6 +26,7 @@ class RingLauncher : Launcher() { mutableMapOf( "AbstractMethod.sortStrings" to BenchmarkEntryWithInit.create(::AbstractMethodBenchmark, { sortStrings() }), "AbstractMethod.sortStringsWithComparator" to BenchmarkEntryWithInit.create(::AbstractMethodBenchmark, { sortStringsWithComparator() }), + "AllocationBenchmark.allocateObjects" to BenchmarkEntryWithInit.create(::AllocationBenchmark, { allocateObjects() }), "ClassArray.copy" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { copy() }), "ClassArray.copyManual" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { copyManual() }), "ClassArray.filterAndCount" to BenchmarkEntryWithInit.create(::ClassArrayBenchmark, { filterAndCount() }), diff --git a/performance/ring/src/main/kotlin/org/jetbrains/ring/AllocationBenchmark.kt b/performance/ring/src/main/kotlin/org/jetbrains/ring/AllocationBenchmark.kt new file mode 100644 index 00000000000..61a8e988e7c --- /dev/null +++ b/performance/ring/src/main/kotlin/org/jetbrains/ring/AllocationBenchmark.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +package org.jetbrains.ring + +var counter = 0 + +open class AllocationBenchmark { + + class MyClass { + fun inc() { + counter++ + } + } + + //Benchmark + fun allocateObjects() { + repeat(BENCHMARK_SIZE) { + MyClass().inc() + } + } + +} \ No newline at end of file