Re: Type atom faster than type integer?
- Posted by DerekParnell (admin) 2 weeks ago
- 187 views
I'm sure the variation you are seeing is just an artifact of your machine's load during testing. Try running each variant (atom/integer) multiple times (e.g. 10) to get an average duration. The integer should be marginally faster, but the difference is usually negligible.
From memory, when using ATOM, Euphoria stores the value as an integer if it can and uses floating-point storage only if needed.
Here is some code that highlights the speed difference.
atom t0 integer n atom m t0 = time() for x = 1 to 5 do n = 0 for y = 1 to 100_000_000 do n += 1 end for end for ? time() - t0 t0 = time() for x = 1 to 5 do m = 0 for y = 1 to 100_000_000 do m += 0.11 end for end for ? time() - t0

