Skip to content

Commit

Permalink
Optimize ImmutableTreeSeq::get(int)
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed May 29, 2024
1 parent 540b74e commit c6d750e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions benchmark/src/main/java/kala/benchmark/TreeSeqBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2024 Glavo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kala.benchmark;

import kala.collection.immutable.ImmutableTreeSeq;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@Warmup(iterations = 5, time = 3)
@Measurement(iterations = 5, time = 3)
@Fork(value = 1)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.Throughput)
@State(Scope.Benchmark)
public class TreeSeqBenchmark {

@Param({"1", "10", "100", "1000", "10000", "100000", "1000000"})
private int length;

private ImmutableTreeSeq<Integer> seq;

@Setup
public void setup() {
Random random = new Random(0);
seq = ImmutableTreeSeq.fill(length, () -> random.nextInt());
}

@Benchmark
public void get(Blackhole bh) {
for (int i = 0; i < length; i++) {
bh.consume(seq.get(i));
}
}
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

allprojects {
group = "org.glavo.kala"
version = "0.74.0"// + "-SNAPSHOT"
version = "0.75.0" + "-SNAPSHOT"

description = "Basic components of Kala"

Expand Down

0 comments on commit c6d750e

Please sign in to comment.