Skip to content

Commit

Permalink
benchmark for QuantilesSketchBufferAggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshug authored and fundead committed Oct 3, 2016
1 parent 97ea13a commit 0d71742
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
69 changes: 69 additions & 0 deletions extensions-core/datasketches/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<relativePath>../../pom.xml</relativePath>
</parent>

<properties>
<jmh.version>1.9.2</jmh.version>
</properties>

<dependencies>
<dependency>
<groupId>com.yahoo.datasketches</groupId>
Expand Down Expand Up @@ -101,6 +105,19 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
Expand All @@ -116,4 +133,56 @@
</dependency>
</dependencies>


<profiles>
<profile>
<id>benchmark</id>

<!-- non provided scope -->
<dependencies>
<dependency>
<groupId>io.druid</groupId>
<artifactId>druid-api</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>io.druid</groupId>
<artifactId>druid-processing</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.openjdk.jmh.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you 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 io.druid.query.aggregation.datasketches.quantiles;

import com.yahoo.sketches.quantiles.QuantilesSketch;
import io.druid.segment.ObjectColumnSelector;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.infra.Blackhole;

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

/**
*/
@State(Scope.Benchmark)
public class QuantilesSketchBufferAggregatorBenchmark
{
private final Random random = new Random(123456789l);

@Benchmark
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public void testit(Blackhole blackhole) throws Exception
{
// final int maxOffheapSize = 1<<18;
final int maxOffheapSize = 1;
QuantilesSketchBufferAggregator aggregator = new QuantilesSketchBufferAggregator(
new ObjectColumnSelector()
{
@Override
public Class classOfObject()
{
throw new UnsupportedOperationException();
}

@Override
public Object get()
{
return random.nextDouble();
}
},
1024,
maxOffheapSize
);

ByteBuffer bb = ByteBuffer.allocate(maxOffheapSize);

aggregator.init(bb, 0);
int n = 1000000;
for (int i = 0; i < n; i++) {
aggregator.aggregate(bb, 0);
}

blackhole.consume(((QuantilesSketch) aggregator.get(bb, 0)).getN());
}
}

0 comments on commit 0d71742

Please sign in to comment.