|
| 1 | +/* |
| 2 | + * Copyright 2016-2019 JetBrains s.r.o. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +// Auto-generated file. DO NOT EDIT! |
| 18 | + |
| 19 | +package benchmarks.immutableList.clojure |
| 20 | + |
| 21 | +import org.openjdk.jmh.annotations.* |
| 22 | +import java.util.concurrent.TimeUnit |
| 23 | +import org.openjdk.jmh.infra.Blackhole |
| 24 | +import benchmarks.* |
| 25 | + |
| 26 | + |
| 27 | +@Fork(1) |
| 28 | +@Warmup(iterations = 5) |
| 29 | +@Measurement(iterations = 5) |
| 30 | +@BenchmarkMode(Mode.AverageTime) |
| 31 | +@OutputTimeUnit(TimeUnit.MICROSECONDS) |
| 32 | +@State(Scope.Thread) |
| 33 | +open class Add { |
| 34 | + @Param("10000", "100000") |
| 35 | + var size: Int = 0 |
| 36 | + |
| 37 | + @Benchmark |
| 38 | + fun addLast(): clojure.lang.PersistentVector { |
| 39 | + return persistentListAdd(size) |
| 40 | + } |
| 41 | + |
| 42 | + @Benchmark |
| 43 | + fun addLastAndIterate(bh: Blackhole) { |
| 44 | + val list = persistentListAdd(size) |
| 45 | + for (e in list) { |
| 46 | + bh.consume(e) |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + @Benchmark |
| 51 | + fun addLastAndGet(bh: Blackhole) { |
| 52 | + val list = persistentListAdd(size) |
| 53 | + for (i in 0 until size) { |
| 54 | + bh.consume(list.get(i)) |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +@Fork(1) |
| 62 | +@Warmup(iterations = 5) |
| 63 | +@Measurement(iterations = 5) |
| 64 | +@BenchmarkMode(Mode.AverageTime) |
| 65 | +@OutputTimeUnit(TimeUnit.MICROSECONDS) |
| 66 | +@State(Scope.Thread) |
| 67 | +open class Get { |
| 68 | + @Param("10000", "100000") |
| 69 | + var size: Int = 0 |
| 70 | + |
| 71 | + private var persistentList = clojure.lang.PersistentVector.EMPTY |
| 72 | + |
| 73 | + @Setup(Level.Trial) |
| 74 | + fun prepare() { |
| 75 | + persistentList = persistentListAdd(size) |
| 76 | + } |
| 77 | + |
| 78 | + @Benchmark |
| 79 | + fun getByIndex(bh: Blackhole) { |
| 80 | + for (i in 0 until size) { |
| 81 | + bh.consume(persistentList.get(i)) |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +@Fork(1) |
| 89 | +@Warmup(iterations = 5) |
| 90 | +@Measurement(iterations = 5) |
| 91 | +@BenchmarkMode(Mode.AverageTime) |
| 92 | +@OutputTimeUnit(TimeUnit.MICROSECONDS) |
| 93 | +@State(Scope.Thread) |
| 94 | +open class Iterate { |
| 95 | + @Param("10000", "100000") |
| 96 | + var size: Int = 0 |
| 97 | + |
| 98 | + private var persistentList = clojure.lang.PersistentVector.EMPTY |
| 99 | + |
| 100 | + @Setup(Level.Trial) |
| 101 | + fun prepare() { |
| 102 | + persistentList = persistentListAdd(size) |
| 103 | + } |
| 104 | + |
| 105 | + @Benchmark |
| 106 | + fun firstToLast(bh: Blackhole) { |
| 107 | + for (e in persistentList) { |
| 108 | + bh.consume(e) |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + @Benchmark |
| 113 | + fun lastToFirst(bh: Blackhole) { |
| 114 | + val iterator = persistentList.listIterator(size) |
| 115 | + |
| 116 | + while (iterator.hasPrevious()) { |
| 117 | + bh.consume(iterator.previous()) |
| 118 | + } |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +@Fork(1) |
| 125 | +@Warmup(iterations = 5) |
| 126 | +@Measurement(iterations = 5) |
| 127 | +@BenchmarkMode(Mode.AverageTime) |
| 128 | +@OutputTimeUnit(TimeUnit.MICROSECONDS) |
| 129 | +@State(Scope.Thread) |
| 130 | +open class Remove { |
| 131 | + @Param("10000", "100000") |
| 132 | + var size: Int = 0 |
| 133 | + |
| 134 | + private var persistentList = clojure.lang.PersistentVector.EMPTY |
| 135 | + |
| 136 | + @Setup(Level.Trial) |
| 137 | + fun prepare() { |
| 138 | + persistentList = persistentListAdd(size) |
| 139 | + } |
| 140 | + |
| 141 | + @Benchmark |
| 142 | + fun removeLast(): clojure.lang.PersistentVector { |
| 143 | + var list = persistentList |
| 144 | + repeat(times = size) { |
| 145 | + list = list.pop() |
| 146 | + } |
| 147 | + return list |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +@Fork(1) |
| 154 | +@Warmup(iterations = 5) |
| 155 | +@Measurement(iterations = 5) |
| 156 | +@BenchmarkMode(Mode.AverageTime) |
| 157 | +@OutputTimeUnit(TimeUnit.MICROSECONDS) |
| 158 | +@State(Scope.Thread) |
| 159 | +open class Set { |
| 160 | + @Param("10000", "100000") |
| 161 | + var size: Int = 0 |
| 162 | + |
| 163 | + private var persistentList = clojure.lang.PersistentVector.EMPTY |
| 164 | + private var randomIndices = listOf<Int>() |
| 165 | + |
| 166 | + @Setup(Level.Trial) |
| 167 | + fun prepare() { |
| 168 | + persistentList = persistentListAdd(size) |
| 169 | + randomIndices = List(size) { it }.shuffled() |
| 170 | + } |
| 171 | + |
| 172 | + @Benchmark |
| 173 | + fun setByIndex(): clojure.lang.PersistentVector { |
| 174 | + repeat(times = size) { index -> |
| 175 | + persistentList = persistentList.assocN(index, "another element") |
| 176 | + } |
| 177 | + return persistentList |
| 178 | + } |
| 179 | + |
| 180 | + @Benchmark |
| 181 | + fun setByRandomIndex(): clojure.lang.PersistentVector { |
| 182 | + repeat(times = size) { index -> |
| 183 | + persistentList = persistentList.assocN(randomIndices[index], "another element") |
| 184 | + } |
| 185 | + return persistentList |
| 186 | + } |
| 187 | +} |
| 188 | + |
| 189 | + |
| 190 | +private fun persistentListAdd(size: Int): clojure.lang.PersistentVector { |
| 191 | + var list = clojure.lang.PersistentVector.EMPTY |
| 192 | + repeat(times = size) { |
| 193 | + list = list.cons("some element") |
| 194 | + } |
| 195 | + return list |
| 196 | +} |
0 commit comments