Last active
August 29, 2015 13:57
-
-
Save gvsmirnov/9682478 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_slow(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_fast(Json json) throws IOException { | |
json.parser.nextToken(); | |
JsonToken token; | |
while ((token = json.parser.nextToken()) != null) { | |
json.parser.nextToken(); | |
if (token != JsonToken.FIELD_NAME) { | |
break; | |
} | |
} | |
} | |
@GenerateMicroBenchmark | |
public void measureSax_new_parser_slow() throws IOException { | |
final JsonParser parser = new JsonFactory().createParser(Json.JSON); | |
parser.nextToken(); | |
JsonToken token; | |
while ((token = parser.nextToken()) != null) { | |
if (token != JsonToken.FIELD_NAME) { | |
break; | |
} | |
parser.nextToken(); | |
} | |
} | |
@GenerateMicroBenchmark | |
public void measureSax_new_parser_fast() throws IOException { | |
final JsonParser parser = new JsonFactory().createParser(Json.JSON); | |
parser.nextToken(); | |
JsonToken token; | |
while ((token = parser.nextToken()) != null) { | |
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.Iteration) | |
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 build/distributions/jmh-gradle-sample-master-0.0.1-benchmarks.jar ".*Parser.*" -f 1 -wi 10 -i 10 -bm avgt -tu us | |
Benchmark Mode Samples Mean Mean error Units | |
s.DummyParserBenchmark.measureSax_fast avgt 10 0.029 0.001 us/op | |
s.DummyParserBenchmark.measureSax_new_parser_fast avgt 10 0.813 0.034 us/op | |
s.DummyParserBenchmark.measureSax_new_parser_slow avgt 10 1.733 0.056 us/op | |
s.DummyParserBenchmark.measureSax_slow avgt 10 0.027 0.001 us/op |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment