Push-Shift vs Double Buffer

JavaScript performance comparison

Test case created

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.

Testing in unknown unknown
Test Ops/sec
Push-Shift Log
for (var I = 0; I < logEntries; I ++) {
pushShiftLog("message");
}
pending…
Double Buffer Log
for (var I = 0; I < logEntries; I ++) {
doubleBufferLog("message");
}
pending…

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

Compare results of other browsers

0 comments

Add a comment