Push-Shift vs Double Buffer
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var maxLength = 1000;
var logEntries = 10000;
var pslog = [];
function pushShiftLog(message) {
if (pslog.length >= maxLength) {
pslog.shift();
}
pslog.push(message);
}
var dblog = 1;
var dblog1 = [];
var dblog2 = [];
function doubleBufferLog(message) {
if (dblog === 1 && dblog1.length >= maxLength) {
dblog2 = [];
dblog = 2;
}
if (dblog === 2 && dblog2.length >= maxLength) {
dblog1 = [];
dblog = 1;
}
if (dblog === 1) {
dblog1.push(message);
} else if (dblog === 2) {
dblog2.push(message);
}
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Push-Shift Log |
|
pending… |
Double Buffer Log |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments