Like this:

[ | sum | sum:= 0. 1 to: 1e9 do: [ :i | sum := sum + i ]. sum ] timeToRun. 

"0:00:00:39.305"

cat bench.c

#include <stdio.h>
#include <time.h>

int main() {
  clock_t begin = clock();

  int sum = 0;
  for (int i = 0; i < 1000000000; i++)
    sum += i;

  clock_t end = clock();
  double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("time_spent=%f\n", time_spent);
}

./a.out

time_spent=2.370234

That is C being 16 times faster ...

> On 17 Dec 2016, at 13:49, Sven Van Caekenberghe <s...@stfx.eu> wrote:
> 
> Hmm, this sounds wrong (C++ should be (a lot) faster on such micro 
> benchmarks).
> 
> You should exclude the executable startup time.
> 
> In Pharo you should do [ .. ] timeToRun and something similar in C/C++.
> 
>> On 17 Dec 2016, at 13:41, Dimitris Chloupis <kilon.al...@gmail.com> wrote:
>> 
>> in multiplication pharo is around 2 times slower compared to C++
>> 
>> #include <stdio.h>
>> 
>> int main()
>> {
>>  double x=1;
>>  for(double i; i<1000000000 ; ++i)
>>    {
>>    x = 0.1*i;
>>    }
>> 
>>  return 1;
>>  }
>> 
>> time ./testMul
>>        3.13 real         3.13 user         0.00 sys
>> 
>> time ./pharo Ephestos.image eval "|x| x := 1. 1 to: 1000000000 do:[:each| x 
>> := 0.1 * each]"
>> 1
>>        4.97 real         4.48 user         0.09 sys
>> 
>> On Sat, Dec 17, 2016 at 2:16 PM Dimitris Chloupis <kilon.al...@gmail.com> 
>> wrote:
>> So I was bored and decided to test how fast pharo is compared to C++. 
>> 
>> so I tested addition 
>> 
>> C++ version:
>> 
>> #include <stdio.h>
>> 
>> int main()
>> {
>>  double x=0;
>>  while(x<1000000000)
>>    {
>>    x = x+1;
>>    }
>> 
>>  return 1;
>>  }
>> 
>> time ./test1
>>        2.84 real         2.84 user         0.00 sys
>> 
>> Pharo version:
>> 
>> time ./pharo Ephestos.image eval "|x| x := 0. 1 to: 1000000000 do:[:each| x 
>> := x +1]"
>> 1
>>        2.09 real         1.94 user         0.08 sys
>> 
>> Pharo is +50% faster than C++ ... o_O ... that's suprising, I assume here 
>> Pharo VM probably does some kind of optimisation. 
>> 
> 


Reply via email to