Minus sign vs Multiply vs Divide vs sub itsefl twice

Edit on GitHub

Setup

var a = [], b = [];
for(var i = 0; i < 100000; i++) a[i]=i;

Tests

  • Minus sign

    for(var i = 0; i < 100000; i++) b[i]=-(a[i]);
  • Multiply

    for(var i = 0; i < 100000; i++) b[i]=-1 * (a[i]);
  • Divide

    for(var i = 0; i < 100000; i++) b[i]=(a[i])/(-1);
  • sub itsefl twice

    for(var i = 0; i < 100000; i++) b[i]=a[i] - a[i]*2;