You are comparing two different types here, double vs a 32 bit integer, and 
program starting time should be excluded.
Something like:

In playground:
Smalltalk garbageCollect.
[ 0 to: 16r0FFFFFFF do: [ :x | ] ] timeToRun.
“ try switch the 0 to 0.0 to have the iterations be on a float, leads to much 
slower time”

C++ (compile with -std=c++11)

#include <iostream>
#include <chrono>

int main(){

                using namespace std::chrono;

                auto start = high_resolution_clock::now();
                for(uint32_t x{0}; x <= 0x0FFFFFFF; ++x){ }
                auto end = high_resolution_clock::now();
                auto ms = duration_cast<milliseconds>(end - start).count();

                std::cout
                                << "time used: "
                                << ms
                                << "ms"
                                << std::endl;
}

Best regards,
Henrik


From: Pharo-users [mailto:pharo-users-boun...@lists.pharo.org] On Behalf Of 
Dimitris Chloupis
Sent: Saturday, December 17, 2016 1:16 PM
To: Any question about pharo is welcome <pharo-users@lists.pharo.org>
Subject: [Pharo-users] [Stupid Benchmarks] C++ vs Pharo

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