this little test may neither be fair nor exact but i still wonder about the outcome...
The Leibniz Formula is a little float Problem for calculating Pi.
I wrote the code in Python and Javascript and let it run on the PyBoard and the Espruino Pico.
Here‘s the Python-Code:
import time
iterations = 1000000
x = 1
pi = 1
start = time.time()
for i in range(2, iterations + 2):
x = x * -1
pi = pi + (x / (2*i-1))
pi = pi * 4
print('Pi: ' + str(pi))
end = time.time()
print('Time taken for ' + str(iterations) + ' Iterations: ' + str((end - start)*1000000) + ' Mikroseconds')
And here‘s the „same“ in Javascript:
var iterations = 1000000;
var x = 1;
var pi = 1;
var begin=Date.now();
for (i = 2; i < iterations + 2; i++) {
x = x * -1;
pi = pi + (x / (2*i-1));
}
pi = pi * 4;
console.log('Pi: ' + pi);
var end= Date.now();
console.log('Took ' + ((end-begin)*1000) + ' Microseconds');
On the PyBoard the code took 26 seconds to execute, the Pico took 458 seconds.
I‘m a little puzzled of the outcome because I though both boards have floating point hardware, or am I wrong?
Can anyone explain the massive speed difference to me?
Thomas
PS: I know that this synthetic benchmark has nothing to do with overall speed, I just want to understand why these numbers are what they are in this particular case.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hello Forum,
this little test may neither be fair nor exact but i still wonder about the outcome...
The Leibniz Formula is a little float Problem for calculating Pi.
I wrote the code in Python and Javascript and let it run on the PyBoard and the Espruino Pico.
Here‘s the Python-Code:
And here‘s the „same“ in Javascript:
On the PyBoard the code took 26 seconds to execute, the Pico took 458 seconds.
I‘m a little puzzled of the outcome because I though both boards have floating point hardware, or am I wrong?
Can anyone explain the massive speed difference to me?
Thomas
PS: I know that this synthetic benchmark has nothing to do with overall speed, I just want to understand why these numbers are what they are in this particular case.