Avatar for user118113

user118113

Member since Sep 2020 • Last active Sep 2020
  • 1 conversations
  • 2 comments

Most recent activity

  • in General
    Avatar for user118113

    Thanks a lot, that was fast! With the cutting edge build a Float32Array sorts correctly about six times faster than with a comparison function. And just as fast as an Int16Array, so I can use full accelerometer precision.

    I'd completely forgotten about the inline C option, I'll try that next if I still need more speed.

    • Jussi
  • in General
    Avatar for user118113

    Hi,

    I need fast array sorting to determine various quantiles from arrays of accelerometer data. I'm using bangle.js and scaling the values to an Int16Array because it seems to sort() twice as fast than a Float32Array, but I get odd results:

    var arr16 = new Int16Array([2,-1,0,-2,1])
    =new Int16Array([2, -1, 0, -2, 1])
    arr16.sort()
    =new Int16Array([-1, -2, 0, 1, 2])

    Clearly it should be [-2, -1, 0, 1, 2].

    arr16.sort((a,b)=>{return a-b}) gets the order correct, but significantly slower than using sort(). An Int16Array of 250 elements sorts at approximately 0.4s with sort() but takes twice as long with the comparison function.

    Or is there some even faster way to sort an array?

    • Jussi
Actions