You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • NICE! --- me: ddddoooohhhh (: ... LOL...

    That's where implicit - wishful - typing by variable naming (trap) kicks in... the 'wrong' name has been chosen for the variable: buffer is not a buffer because it is called so... ;(

    I made a rough performance test, and it shows that slice is still about 6 times slower (even with some optimization / moving the var s out of loop)... memory is for sure contributing to the time aspect... - you can directly run the attached .html file by just clicking on the link. Test on Espruino still pending.

    <html><head><title>typedBuffedSliced</title></head>
    <body><h3>typedBuffedSliced</h3>
    <button onclick="exec()">exec()</button>
    <script>
    var C = {
     OLED_WIDTH                 : 128,
     OLED_CHAR                  : 0x40,
     OLED_CHUNK                 : 128
    }, WIDTH = 128, HEIGHT = 64;
    function exec() {
      var buf = new Uint8Array((WIDTH*HEIGHT) / 8), bLen = buf.length;
      var chunk = new Uint8Array(C.OLED_CHUNK+1), cLen = chunk.length;
      console.log("buf: " + bLen + " - chunk: " + cLen);
      chunk[0] = C.OLED_CHAR;
      var p, pe, c1, t10, t11, slice, c2, t20, t21, cL = C.OLED_CHUNK;
      for (p=0; p < bLen; p += C.OLED_CHUNK) { pe = p + C.OLED_CHUNK;
        t10 = new Date().getTime(); for (c1 = 0; c1 < 100000; c1++) {
          chunk.set(new Uint8Array(buf.buffer,p,cL), 1);
        } t11 = new Date().getTime();
        t20 = new Date().getTime(); for (c2 = 0; c2 < 100000; c2++) {
          chunk.set(buf.slice(p, pe), 1);
        } t21 = new Date().getTime();
        console.log(p+"-"+(pe)+": " + ((t21 - t20) / (t11 - t10)));
      }
    }
    </script>
    <pre>
    Console:
    buf: 1024 - chunk: 129
    0-128: 4.375
    128-256: 5.529411764705882
    256-384: 7.142857142857143
    384-512: 7.142857142857143
    512-640: 7.846153846153846
    640-768: 5.875
    768-896: 6.928571428571429
    896-1024: 7.615384615384615
    </pre>
    </body>
    </html>
    

    PS: updated - (line 18 had buf.buf and passing undefined which did speed it up to factor 2)


    2 Attachments

About

Avatar for allObjects @allObjects started