Skip to content

Instantly share code, notes, and snippets.

@andreafey
Created February 21, 2014 23:35
Show Gist options
  • Save andreafey/9145961 to your computer and use it in GitHub Desktop.
Save andreafey/9145961 to your computer and use it in GitHub Desktop.
hashtable timer
var table = new SimpleHashTable
// generate 10000 entries
// A to Z a to z ascii entries
val range = (65 to 90) ++ (97 to 122)
var count = 0
val chars = for {
a <- range
b <- range
c <- range
} yield List(a.toChar, b.toChar, c.toChar).mkString
for ((str, index) <- chars.zipWithIndex if index < 10000) table.addKeyValuePair(str, index)
// start timer
val start = System.nanoTime()
for ((str, index) <- chars.zipWithIndex if index < 1000) table.getValue(str)
// end timer
val end = System.nanoTime()
System.out.println("millis elapsed: " + (end - start)/1000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment