[Newbies] Primitives and array computation
Frederic Dambreville
squeak at fredericdambreville.com
Thu Jul 10 16:47:21 UTC 2008
Hi,
I have to build a class which makes intensive mathematical
computations (which I will connect to a Squeak GUI).
For this purpose, I tried the mathematical functions on arrays, and
evaluated the performances:
Examples:
Time millisecondsToRun: [
tab1:=(1 to: 1000000).
tab1 collect: [:each | each cos]]
7716
Time millisecondsToRun: [
(1 to: 1000000) cos]
7780
Time millisecondsToRun: [
tab1:=(1 to: 1000000).
tab1 do: [:each | each cos]]
1231
The best is about 1s for computing cos(x) 1000000 times.
By reducing the the vector size, the three algorithms seem to be
equivalent in time (I guess that there are additional time consumed
for memory management).
Now, in comparison, the same tests for a C implementation is about
0.002s, about 500x better.
By browsing the classes, it did not saw primitives acting directly on
arrays, and it seemed that the loops are done by Squeak...
An explanation of this dramatical difference.
So, my question is: does the VM implements primitives for computing
mathematical functions on arrays?
Best regards,
FD
More information about the Beginners
mailing list