Skip to content

Instantly share code, notes, and snippets.

@nitsanw
nitsanw / gist:4587751
Last active December 11, 2015 10:38
Ivy.xml to bring in Caliper
<ivy-module version="2.0">
<info organisation="psy.lob.saw" module="experiments"/>
<dependencies>
<dependency org="com.google.caliper" name="caliper" rev="0.5-rc1">
<exclude name='java-allocation-instrumenter' />
</dependency>
</dependencies>
</ivy-module>
@nitsanw
nitsanw / gist:4587927
Last active December 11, 2015 10:38
Hand rolled benchmarking for UTF8 encoding
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
@nitsanw
nitsanw / gist:4587995
Created January 21, 2013 18:07
Caliper benchmark of UTF8 string encoding
package utf8;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
@nitsanw
nitsanw / gist:4588102
Created January 21, 2013 18:23
Caliper output of UTF8 benchmark
0% Scenario{vm=java, trial=0, benchmark=CustomEncoder, direct=true, stringsFile=utf8.txt} 107419.06 ns; σ=1032.57 ns @ 4 trials
17% Scenario{vm=java, trial=0, benchmark=StringGetBytes, direct=true, stringsFile=utf8.txt} 199795.25 ns; σ=6067.76 ns @ 10 trials
33% Scenario{vm=java, trial=0, benchmark=CharsetEncoder, direct=true, stringsFile=utf8.txt} 278708.17 ns; σ=10344.13 ns @ 10 trials
50% Scenario{vm=java, trial=0, benchmark=CustomEncoder, direct=false, stringsFile=utf8.txt} 102597.54 ns; σ=3081.05 ns @ 10 trials
67% Scenario{vm=java, trial=0, benchmark=StringGetBytes, direct=false, stringsFile=utf8.txt} 196083.46 ns; σ=4185.70 ns @ 10 trials
83% Scenario{vm=java, trial=0, benchmark=CharsetEncoder, direct=false, stringsFile=utf8.txt} 185340.89 ns; σ=17881.00 ns @ 10 trials
benchmark direct us linear runtime
CustomEncoder true 107 ===========
CustomEncoder false 103 ===========
@nitsanw
nitsanw / gist:4589685
Last active December 11, 2015 10:48
Run a benchmark with measureMemory sorted
<target name="benchmark-utf8-encoding" depends="build,download-allocation-jar" description=" run experiments">
<ivy:cachepath pathid="lib.path.id" />
<java classpathref="lib.path.id" classname="utf8.Utf8EncodingBenchmark" fork="true">
<classpath>
<pathelement path="${build.dir}"/>
<pathelement location="${allocation.jar.file}"/>
</classpath>
<env key="ALLOCATION_JAR" value="${allocation.jar.file}"/>
<arg value="--measureMemory" />
</java>
@nitsanw
nitsanw / gist:4589721
Created January 21, 2013 21:40
UTF8 benchmark output with allocation
benchmark-utf8-encoding:
[java] 0% Scenario{vm=java, trial=0, benchmark=CustomEncoder, direct=true, stringsFile=utf8.txt} 99842.67 ns; σ=741.65 ns @ 3 trials, allocated 0 instances for a total of 0B
[java] 17% Scenario{vm=java, trial=0, benchmark=StringGetBytes, direct=true, stringsFile=utf8.txt} 204718.91 ns; σ=11685.98 ns @ 10 trials, allocated 2672 instances for a total of 166024B
[java] 33% Scenario{vm=java, trial=0, benchmark=CharsetEncoder, direct=true, stringsFile=utf8.txt} 267964.76 ns; σ=2541.32 ns @ 3 trials, allocated 0 instances for a total of 0B
[java] 50% Scenario{vm=java, trial=0, benchmark=CustomEncoder, direct=false, stringsFile=utf8.txt} 102537.55 ns; σ=5065.85 ns @ 10 trials, allocated 0 instances for a total of 0B
[java] 67% Scenario{vm=java, trial=0, benchmark=StringGetBytes, direct=false, stringsFile=utf8.txt} 202675.42 ns; σ=6581.97 ns @ 10 trials, allocated 2672 instances for a total of 166024B
[java] 83% Scenario{vm=java, trial=0, benchmark=CharsetEncode
@nitsanw
nitsanw / gist:4758225
Last active December 12, 2015 10:19
Unaligned memory concurrent access atomicity test
public class DirectByteBufferUnalignedInLineAtomicityTests {
public abstract static class ByteBufferTest implements
Actor1_Effector1_Test<ByteBuffer, long[]> {
@Override
public ByteBuffer newState() {
return allocateNaughtyBuffer(getSize());
}
abstract int getSize();
@nitsanw
nitsanw / gist:4758322
Last active December 12, 2015 10:18
Results for running atomicity test across cache lines
$ java -jar target/java-concurrency-torture.jar -v -time 1000 -t .*DirectByteBufferUnalignedCrossLineAtomicityTests.*LongTest
Java Concurrency Torture Tests
---------------------------------------------------------------------------------
Running in forked mode...
Running each test for 1000ms
Each test does 10 internal loops
Look in results.html for the results
Running org.openjdk.concurrent.torture.tests.atomicity.crosscache.DirectByteBufferUnalignedCrossLineAtomicityTests$LongTest
@nitsanw
nitsanw / gist:4758402
Last active December 12, 2015 10:19
Concurrent unaligned memory access within the cache line
Running org.openjdk.concurrent.torture.tests.atomicity.buffers.DirectByteBufferUnalignedInLineAtomicityTests$LongTest
Executing with 2 threads x 2 groups = 4 threads
Iterations .
Observed state Occurrences Expectation Interpretation
[0] ( 1327957) UNKNOWN N/A
[-1] ( 1336273) UNKNOWN N/A
@nitsanw
nitsanw / gist:4761109
Created February 12, 2013 09:10
Concurrent unaligned memory access fails
Running org.openjdk.concurrent.torture.tests.atomicity.buffers.DirectByteBufferUnalignedInLineAtomicityTests$LongTest
Executing with 2 threads x 2 groups = 4 threads
Iterations .
Observed state Occurrences Expectation Interpretation
[-1] ( 2139678) UNKNOWN N/A
[0] ( 2397091) UNKNOWN N/A
[-4294967296] ( 1) UNKNOWN N/A
.
Observed state Occurrences Expectation Interpretation
[-1] ( 4365283) UNKNOWN N/A