Some of my software engineering friends and I often discuss the concept of infinity and how near it actually is, be it in the form of the infinite number of points on any circle regardless of the circumference or taking an infinite number of half steps between here and there resulting in never actually getting all the way there — which is what coding in javascript has felt like for me. When attempting to compute large numbers with accurate precision (meaning without scientific notation rounding lossiness) or when bumping into a tiny infinity boundary due to memory limitations of the javascript interpretor engine’s process.

This week I worked to port javascript code that was performing JSON TO SOAP/XML message transformation on a Java 1.8 Jetty powered API gateway. As a result of changing the programming model from interpreted js that needed to be compiled for every message passing through the API gateway to precompiled java components that instead read declarative configuration properties from a BPEL process the performance improved by a factor of 4.

With regards to bumping into a tiny infinity in js when performing simple math operations such as the addition of large numbers, this js performance test is a simple way to benchmark the speed of one’s javascript interpreter ( http://ariya.ofilabs.com/tag/v8 ) while also getting to experience that infinity is just a handful of milliseconds away as this code bumps into that wall after just 1477 additions of fibonacci integers. I won’t even waste your time with the version that slowly tests to see if each product is prime.

# Content and Code Copyright @iryanb http://www.guarden.io 2016 All Rights Reserved, per the terms and conditions of the Creative Commons BY SA License

window.addEventListener(‘load’, function(e) {

document.querySelector(‘#test’).innerHTML = ‘fibonacci (Phi) Javascript performance test’;

}, false);

var x = 1;

var y = 1;

var n = 1;

var f = 1;

var start = Date.now();

document.writeln(“Phi @iryanb Perf Test ©®™” + “<br />”);

for(n = 3; n < 1478; n++){

f=x+y;

t=Math.abs(Date.now() – start);

document.writeln(“🌀 : ” + n + ” is ” + f + ” Time(ms): ” + t);

x=y;

y=f;

document.writeln(” <br />”);

}

var TotalTime = “average”;

if (t < 24) { TotalTime = “fast”;}

if (t > 50) { TotalTime = “slow”;}

document.writeln(“Results: ” + TotalTime );

Try this code in the JSAnywhere app on your Smartphone to experience the speed of math in js on a mobile device.

benchmark results:

Note an iPhone6 is 4 to 5 times faster at js math than an iPhone4.

iPhone6…

🌀 : 1475 is 8.077637632156222e+307 Time(ms): 21

🌀 : 1476 is 1.3069892237633987e+308 Time(ms): 21

🌀 : 1477 is Infinity Time(ms): 21

iPhone4…

🌀 : 1475 is 8.077637632156222e+307 Time(ms): 104

🌀 : 1476 is 1.3069892237633987e+308 Time(ms): 104

🌀 : 1477 is Infinity Time(ms): 104