jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
<script src="http://jshashtable.googlecode.com/svn/trunk/hashtable.js"></script>
<script>
// @getify's solution
var Set = (function() {
var indexOf = Array.prototype.indexOf;
if (typeof indexOf !== 'function') {
indexOf = function(value) {
for (var index = 0, length = this.length; index < length; index++) {
if (this[index] === value) {
return index;
}
}
return -1;
};
}
function Set() {
this.set = [];
}
Set.prototype = {
'constructor': Set,
'put': function(key, value) {
var index = indexOf.call(this.set, key);
if (index !== -1 && index % 2 === 0) {
this.set.splice(index, 2);
}
this.set.push(key, value);
},
'get': function(key) {
var index = indexOf.call(this.set, key);
return (index !== -1 && index % 2 === 0) ? this.set[++index] : null;
},
'containsKey': function(key) {
var index = indexOf.call(this.set, key);
return (index !== -1 && index % 2 === 0);
},
'containsValue': function(value) {
var index = indexOf.call(this.set, value);
return (index !== -1 && index % 2 !== 0);
},
'remove': function(key) {
var index = indexOf.call(this.set, key),
value = null;
if (index !== -1 && index % 2 === 0) {
value = this.set.splice(index, 2)[1];
}
return value;
}
};
return Set;
}());
var hash = new Hashtable(),
set = new Set();
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Hashtable Operations |
| ready |
Set Operations |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.