forked from isaacs/fast-list
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add insert benchmark and update readme
Also try adjust to original semi-colon style Closes isaacs#5
- Loading branch information
Krzysztof Chrapka
committed
Jan 23, 2014
1 parent
5606a22
commit c919f58
Showing
6 changed files
with
141 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var bench = require("bench") | ||
|
||
var l = 50 | ||
, FastList = require("../fast-list.js") | ||
|
||
exports.countPerLap = l | ||
//exports.stepsPerLap = 10 | ||
|
||
|
||
exports.compare = | ||
{ "random []": function () { | ||
var list = [] | ||
for (var i = 0; i < l; i++) { | ||
list.splice(Math.random()*(list.length+1), 0, i) | ||
} | ||
} | ||
, "random FastList()": function () { | ||
var list = new FastList() | ||
var map = [null] | ||
for (var i = 0; i < l; i++) { | ||
var before = map[Math.random()*map.length] | ||
if(!map[before]){ | ||
map.push(list.push(i)) | ||
} else { | ||
map.insertBefore(map[before], i) | ||
} | ||
} | ||
} | ||
} | ||
|
||
bench.runMain() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var bench = require("bench") | ||
|
||
var l = 5000 | ||
, FastList = require("../fast-list.js") | ||
|
||
exports.countPerLap = l | ||
exports.stepsPerLap = 10 | ||
|
||
|
||
exports.compare = | ||
{ "random []": function () { | ||
var list = [] | ||
for (var i = 0; i < l; i++) { | ||
list.splice(Math.random()*(list.length+1), 0, i) | ||
} | ||
} | ||
, "random FastList()": function () { | ||
var list = new FastList() | ||
var map = [null] | ||
for (var i = 0; i < l; i++) { | ||
var before = map[Math.random()*map.length] | ||
if(!map[before]){ | ||
map.push(list.push(i)) | ||
} else { | ||
map.insertBefore(map[before], i) | ||
} | ||
} | ||
} | ||
} | ||
|
||
bench.runMain() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters