News for hackers. Stuff that matters.
Re:Making the obvious code fast (2016) by bufferoverflow on Wednesday April 17, 2019 @10:35AM (#19682909)
I tried JS in chrome, and the best I got was 78ms on i7-8750H

    <script>
    let arr = new Float64Array(32000000);
    let sum = new Float64Array(1);
    sum[0] = 0;
    let l = arr.length, i, el;
    // Initialize with radom values
    for (i=0; i<l; i++) arr[i] = Math.random();

    // Sum
    let st = performance.now();
    for (i=0; i<l; i++) sum[0] += arr[i] * arr[i];
    let en = performance.now();
    console.log(en - st, sum[0]);
    </script>
Using a temporary value for arr[i] is definitely slower.

There are no comments on this comment yet.