Hmm, I've run some benchmark tests (I ran them online on Chrome so I don't know how reliable they are) and I got two different results on two different sites. On the first site (jsben.ch/) it seems that for smaller numbers, the iterative way is faster, the real power of the pure math function is when the N >= 200. While on the other site (perf.zone/), the math function is way faster even for smaller numbers. I got this results on the perf.zone/quick:
for N = 20, math -> 705,738,258 op/second; iterative -> 66,518,777 op/second
for N = 50, math -> 725,140,230 op/second; iterative -> 16,581,587 op/second
for N = 100, math -> 700,447,370 op/second; iterative -> 5,875,773 op/second
for N = 200, math -> 706,141,355 op/second; iterative -> 2,562,412 op/second
But anyway I wonder what time complexity does Javascript Math functions have π€.
Hmm, I've run some benchmark tests (I ran them online on Chrome so I don't know how reliable they are) and I got two different results on two different sites. On the first site (jsben.ch/) it seems that for smaller numbers, the iterative way is faster, the real power of the pure math function is when the N >= 200. While on the other site (perf.zone/), the math function is way faster even for smaller numbers. I got this results on the perf.zone/quick:
But anyway I wonder what time complexity does Javascript Math functions have π€.
The variance is very interesting. I wonder if Chrome throttles certain calculations.
I think it does.