CoCalc Shared Filestest / bench2.sagewsOpen in CoCalc with one click!
Author: William A. Stein
%time %r s <- 0 for (n in 0:1000000){ s <- s + n } print(s)
[1] 500000500000 CPU time: 0.00 s, Wall time: 0.41 s
%time %python s=0 for n in range(0,1000000 + 1): s += n print s
500000500000 CPU time: 1.59 s, Wall time: 1.60 s
%time %python import numpy v = numpy.arange(1000001) numpy.sum(v)
500000500000 CPU time: 0.00 s, Wall time: 0.00 s
%time %r s <- 0:1000000 print(sum(as.numeric(s)))
[1] 500000500000 CPU time: 0.00 s, Wall time: 0.07 s
%time %julia s = 0 for i = 1:1000000 s += i end print(s)
500000500000 CPU time: 0.00 s, Wall time: 0.20 s
%time %julia sum(linspace(1,1000000,1000000))
5.000005e11 CPU time: 0.00 s, Wall time: 0.00 s