Created
March 21, 2014 09:57
-
-
Save gvsmirnov/9682967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import com.fasterxml.jackson.core.JsonFactory; | |
import com.fasterxml.jackson.core.JsonParser; | |
import com.fasterxml.jackson.core.JsonToken; | |
import org.openjdk.jmh.annotations.*; | |
import java.io.IOException; | |
public class DummyParserBenchmark { | |
@GenerateMicroBenchmark | |
public void measureSax_pre_check(Json json) throws IOException { | |
json.parser.nextToken(); | |
JsonToken token; | |
while ((token = json.parser.nextToken()) != null) { | |
if (token != JsonToken.FIELD_NAME) { | |
break; | |
} | |
json.parser.nextToken(); | |
} | |
} | |
@GenerateMicroBenchmark | |
public void measureSax_post_check(Json json) throws IOException { | |
json.parser.nextToken(); | |
JsonToken token; | |
while ((token = json.parser.nextToken()) != null) { | |
json.parser.nextToken(); | |
if (token != JsonToken.FIELD_NAME) { | |
break; | |
} | |
} | |
} | |
@State(Scope.Thread) | |
public static class Json { | |
private static final String JSON = "{\"key\":\"value\"}"; | |
private JsonParser parser; | |
@Setup(Level.Invocation) | |
public void init() throws IOException { | |
parser = new JsonFactory().createParser(JSON); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ java -jar microbenchmarks.jar ".*Parser.*" -bm avgt -tu us | |
Benchmark Mode Samples Mean Mean error Units | |
s.DummyParserBenchmark.measureSax_post_check avgt 200 0.509 0.005 us/op | |
s.DummyParserBenchmark.measureSax_pre_check avgt 200 0.748 0.007 us/op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
perfCompile 'org.openjdk.jmh:jmh-core:0.5.3' | |
perfCompile 'org.openjdk.jmh:jmh-generator-annprocess:0.5.3' | |
perfCompile 'com.fasterxml.jackson.core:jackson-core:2.3.2' | |
perfCompile 'com.fasterxml.jackson.core:jackson-databind:2.3.2' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment