Re: [tutor] benchmark: integer float atom
- Posted by petelomax May 25, 2020
- 1139 views
Maybe there is a reason for the Phix results...
Since 42.0, n-1.0, and n-2.0 are all atoms, there is no typecheck for (atom n), however the compiler cannot be sure that the expressions n-1 and n-2 will not ever dip below MININT, so (integer n) emits a fairly quick type check. In some cases, integer n1 = n-1 and the like may help, but I doubt that is the case here. [Note that without typecheck prevents the invocation of udts (user-defined types) and may suppress some builtin tests but is by no means guaranteed to skip them all - in fact doing so would actually slow some things down.] I feel confident other tests will show integer is often quite a bit faster than atom.
Obviously an iterative approach would be much faster, but if you are looking for some truly impressive speed, mpz_fib_ui(res,4784969) completes in 0.1s, and that's a million-digit result! Admittedly generating a million-digit string takes about 2s.