[Squeak-fr] Fwd: Naive number questions

stéphane ducasse ducasse at iam.unibe.ch
Mer 3 Nov 10:49:44 CET 2004



Begin forwarded message:

> From: John M McIntosh <johnmci at smalltalkconsulting.com>
> Date: 2 novembre 2004 23:10:26 GMT+01:00
> To: The general-purpose Squeak developers list  
> <squeak-dev at lists.squeakfoundation.org>
> Subject: Re: Naive number questions
> Reply-To: The general-purpose Squeak developers list  
> <squeak-dev at lists.squeakfoundation.org>
>
> a) Well the large positive integer 100,000,000,000 that x is  
> incrementing to becomes expensive to use.
>
> b) The Java solution just uses 64 bit integers, which on some  
> platforms might have hardware support.
> Now if the Java folks could give us oh say a few % of the money they  
> spent on Java, say a few tens of million, then we too
> could develop a faster Squeak VM. Besides it is a JIT and those  
> millions produce native instructions.
>
> c) By using timesRepeat: you actually are doing message sends to do  
> the increment. That's very very expensive, take a look at
> the bytecodes that are compiled...
>
> Try
>
> Time millisecondsToRun: [
> | x |
> x := 0.
> 0 to: 1000 do: [:i |
> 	0 to: 100000000 do: [: j|
> 		x _ x + 1.
> ]]]
>
> That produces a much more performance friendly bytecode sequence, and  
> matchs more the spirit of the Java code.
>
>
> PS did you try a VW version? Also try using floating point too and see  
> what happen.
>
>
> On Nov 2, 2004, at 12:41 PM, stéphane ducasse wrote:
>
>> hi guys
>>
>> one guy in the french mailing llist posted that:
>>
>> In Java
>>
>>   long x = 0;
>>     long timeStart = 0;
>>  
>>     timeStart = System.currentTimeMillis();
>>  
>>     for (int i = 0; i < 1000; i++) {
>>         for (int j = 0; j < 100000000; j++) {
>>             x = x + 1;
>>         }
>>     }
>>  
>>     timeStart = System.currentTimeMillis() - timeStart;
>>     System.out.println(new Long(timeStart).toString());
>>     System.out.println(new Long(x).toString());
>>  
>> ==> 487 secondes.
>>
>> in Squeak: but it took a lot more (in fact I stopped it).
>> Is there any reason why?
>>
>> Time millisecondsToRun: [
>> | x |
>> x := 0 .
>> 1000 timesRepeat: [
>> 	100000000 timesRepeat: [ x := x + 1 ] ] ].
>>
>> Stef
>>
>>
>>
>>
>>
> --
> ======================================================================= 
> ====
> John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> ======================================================================= 
> ====
>
>
>



Plus d'informations sur la liste de diffusion Squeak-fr