Skip to content

Instantly share code, notes, and snippets.

@seratch
Created December 3, 2011 11:44
Show Gist options
  • Save seratch/1426936 to your computer and use it in GitHub Desktop.
Save seratch/1426936 to your computer and use it in GitHub Desktop.
urlencode instant benchmark script
@Grab('commons-codec:commons-codec:1.2')
import org.apache.commons.codec.net.URLCodec;
def input = URLDecoder.decode("http://www.google.co.jp/?q=URLEncoder%E3%81%AF%E3%81%A9%E3%82%8C%E3%81%8F%E3%82%89%E3%81%84%E9%81%85%E3%81%84%E3%81%AE%E3%81%8B%E3%80%81commons-codec%E3%81%A8%E6%AF%94%E8%BC%83%E3%81%97%E3%81%A6%E3%81%BF%E3%81%BE%E3%81%99", "UTF-8")
int times = 1000000;
class Stopwatch {
Integer startTime = null
Integer endTime = null
def start() { startTime = System.currentTimeMillis() }
def stop() { endTime = System.currentTimeMillis() }
def result() { endTime - startTime }
}
// execute separetely
// commons-codec
def sw = new Stopwatch()
def codec = new URLCodec("UTF-8")
sw.start()
for(def i=0; i<times; i++) {
encoded = codec.encode(input)
}
sw.stop()
println(sw.result() / times)
// java.net.URLEncoder
def sw = new Stopwatch()
sw.start()
for(def i=0; i<times; i++) {
encoded = URLEncoder.encode(input, "UTF-8")
}
sw.stop()
println(sw.result() / times)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment