jshashtable vs. native object

Benchmark created on


Description

Performance comparison between jshashtable implementation (http://www.timdown.co.uk/jshashtable/) vs. native javascript objects

Preparation HTML

<script src="//jshashtable.googlecode.com/files/jshashtable-2.1.js">
</script>
<script>
  var jsobject = {};
  var jshashtable = new Hashtable();
  var sampleKey = Math.random().toString();
  var sampleValue = Math.random().toString();
  
  var initialSize = 1000000;
  for (var index = 0; index < initialSize; index++) {
    var key = Math.random().toString();
    var val = Math.random().toString();
    jsobject[key] = val;
    jshashtable.put(key, val);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
native object - create
jsobject = {};
ready
jshashtable - create
jshashtable = new Hashtable();
ready
native object - insert
jsobject[sampleKey] = sampleValue;
ready
jshashtable - insert
jshashtable.put(sampleKey, sampleValue);
ready
native object - get
var result = jsobject[sampleKey];
ready
jshashtable - get
var result = jshashtable.get(sampleKey);
ready
native object - remove
delete jsobject[sampleKey];
ready
jshashtable - remove
jshashtable.remove(sampleKey);
ready
native object - each
for (var key in jsobject) {
  var result = key + jsobject[key];
}
ready
jshashtable - each
jshashtable.each(function(key, val) {
  var result = key + val;
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.