Naive number questions
Bert Freudenberg
bert at impara.de
Wed Nov 3 15:28:23 UTC 2004
Am 02.11.2004 um 22:42 schrieb Andreas Raab:
> Besides, one of the more interesting things to do is to not use
> "long/int" but rather the Object integer type.
Yep. On my machine the speed then is almost equal. Mind you, Squeak
Interpreter vs. Java JIT:
| x |
x := 0.
(Time millisecondsToRun: [
1 to: 2 do: [: i|
1 to: 100000000 do: [:j | x := x + 1]]]) -> x
80244->200000000
=================
class Numtest
{
public static void main(String args[]) {
Long x;
Long timeStart;
Integer one = new Integer(1);
x = new Long(0);
timeStart = new Long(System.currentTimeMillis());
for (Integer i = new Integer(0); i.intValue() < 2; i=new
Integer(i.intValue()+one.intValue())) {
for (Integer j = new Integer(0); j.intValue() < 100000000; j=new
Integer(j.intValue()+one.intValue())) {
x = new Long(x.longValue() + one.longValue());
}
}
timeStart = new Long(System.currentTimeMillis() -
timeStart.longValue());
System.out.println(timeStart.toString());
System.out.println(x.toString());
}
}
% java -version
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-141.3)
Java HotSpot(TM) Client VM (build 1.4.2-38, mixed mode)
% javac Numtest.java && java Numtest
66851
200000000
==============
Squeak: 80 seconds
Java: 66 seconds
Meaning they are almost equal, with Java being faster by 20%, but by
not several orders of magnitude. Not bad for a pure Interpreter, I'd
say. Would be interesting to try with Auto-Boxing/Unboxing, but I don't
have a newer Java version installed.
- Bert -
More information about the Squeak-dev
mailing list
|