/* Ahl's Benchmark in Picat. From https://twitter.com/Frinklang/status/1620698584424546306 """ Is your computer (or phone) faster than a Cray-1 supercomputer? Here's a benchmark from Creative Computing magazine from March, 1984: Original article: https://archive.org/details/creativecomputing-1984-03/page/n7/mode/1up Frink program: https://frinklang.org/fsp/colorize.fsp?f=AhlsBenchmark.frink Frink runs it in 0:00.003 on my laptop after JVM warmup. """ This Picat program is a port of Alan's Frink code: https://frinklang.org/fsp/colorize.fsp?f=AhlsBenchmark.frink """ Ahl's simple benchmark, Creative Computing March 1984, P. 6 https://archive.org/details/creativecomputing-1984-03/page/n7/mode/1up """ Running from command line: $ time picat -g "time(go)" ahls_benchmark.pi Accuracy: 6.821210e-13 Random: 4.1 Time: 0ms Accuracy: 6.821210e-13 Random: 1.0 Time: 1ms Accuracy: 6.821210e-13 Random: 2.4 Time: 0ms Accuracy: 6.821210e-13 Random: 10.5 Time: 0ms Accuracy: 6.821210e-13 Random: 23.6 Time: 2ms Accuracy: 6.821210e-13 Random: 8.1 Time: 1ms Accuracy: 6.821210e-13 Random: 7.5 Time: 1ms Accuracy: 6.821210e-13 Random: 15.0 Time: 0ms Accuracy: 6.821210e-13 Random: 16.5 Time: 0ms Accuracy: 6.821210e-13 Random: 11.1 Time: 0ms CPU time 0.005 seconds. picat -g "time(go)" ahls_benchmark.pi 0,02s user 0,02s system 98% cpu 0,041 total Running from the Picat REPL gives the about same performance: the CPU time ranges from 0.001..0.01 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. go => statistics(runtime,_), foreach(_Times in 1..10) statistics(runtime,[_,Start]), S = 0, R = 0, foreach(N in 1..100) A = N, foreach(I in 1..10) A := sqrt(A), R := R + frand() end, foreach(I in 1..10) A := A**2, R := R + frand() end, S := S + A end, printf("Accuracy: %e\n",abs(1010-S/5)), printf("Random: %3.1f\n",abs(1000-R)), statistics(runtime,[_,End]), printf("Time: %dms\n",End-Start), nl end, nl.