Created
July 20, 2015 19:11
-
-
Save 02JanDal/eb2d43a6aaadd962c9f1 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
#!/usr/bin/env groovy | |
import groovy.json.internal.JsonFastParser | |
import groovy.transform.CompileStatic | |
import groovy.transform.Field | |
@Field | |
JsonFastParser jsonParser = new JsonFastParser(false, false, false, false) | |
@Field | |
char[] data = new File("json.json").text.toCharArray() | |
@CompileStatic | |
void benchmark1() { | |
def iterations = 10000 | |
def timeBegin = System.nanoTime() | |
for (int i = 0; i < iterations; i++) { | |
jsonParser.parse(data) | |
} | |
def timeEnd = System.nanoTime() | |
def time = timeEnd - timeBegin | |
println time / (iterations * 1000 * 1000 * 1000) | |
} | |
void benchmark2(Map it) { | |
def iterations = 10000 | |
def timeBegin = System.nanoTime() | |
for (int i = 0; i < iterations; i++) { | |
it.versions.time.max() as int | |
} | |
def timeEnd = System.nanoTime() | |
def time = timeEnd - timeBegin | |
println time / (iterations * 1000 * 1000 * 1000) | |
} | |
print "value: json groovy - parse_time " | |
benchmark1() | |
print "value: json groovy - access_time " | |
benchmark2(jsonParser.parse(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment