Skip to content

Instantly share code, notes, and snippets.

@02JanDal
Created July 20, 2015 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 02JanDal/eb2d43a6aaadd962c9f1 to your computer and use it in GitHub Desktop.
Save 02JanDal/eb2d43a6aaadd962c9f1 to your computer and use it in GitHub Desktop.
#!/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