insert vs underscore binary
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.2/underscore-min.js"></script>
var _views = [];
var _currentIndex = -1;
var a = [];
var aIndex = -1;
var _insert = function(uid) {
var found = false;
for (var i = 0; i < _views.length; i++) {
var currentUid = _views[i];
if (uid < currentUid) {
_views.splice(i, 0, uid);
_currentIndex = i;
found = true;
break;
} else if (uid === currentUid) {
_currentIndex = i;
found = true;
break;
}
}
if (!found) {
_views.push(uid);
_currentIndex = i;
}
};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
insert |
|
pending… |
underscore sorted insert |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments