Skip to content

Instantly share code, notes, and snippets.

@jack128
Created December 16, 2013 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jack128/7983236 to your computer and use it in GitHub Desktop.
Save jack128/7983236 to your computer and use it in GitHub Desktop.
javascript vs Delphi perf test. see here delphi code https://forums.embarcadero.com/thread.jspa?threadID=74930
function itg (x) { return x*x; }
var vp = 50000;
var np = 0;
var snp = np;
var step = 0.0001;
var sum = 0;
console.log('Integral calculations...');
var cnt1 = Date.now();
while (np + step < vp) {
//sum = sum + (itg(np) + itg(np + step)) / 2*step;
sum = sum + ((np*np + (np + step)*(np + step))) / 2 * step;
np = np + step;
}
var cnt2 = Date.now();
var cnt3 = cnt2 - cnt1;
console.log('Integral from ' + snp + ' to ' + vp +
' step ' + step + ' is equal ' + sum +
'Difference: ' + (cnt3 / 1000) + ' seconds');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment