I tried to run the same program on both Ruby and Crystal. In the program, there is no code which controls threads.
As for Ruby, Only 1 core is used and the usage is 100% through the program as following screen shot indicates
and the report of time command is
real 5m21.168s user 5m20.784s sys 0m0.296s
As for crystal, all cores are used and the usage of CPU about 170%.
and time report is
real 1m51.299s user 2m25.876s sys 0m48.380s
Does this mean that the compiler of crystal does specific work to build a binary which uses cores reasonably? If so, is there any way to create a binary which runs on only 1 core like Ruby?
condition
- CPU: Intel core i7 6700
- OS: Ubuntu 16.04 64bit
- Ruby version: 2.4.0-preview2
- Crystal version: 0.18.7 / 0.19.1
----------- added following description on 13th/Sep 2016 --------------
code
- Crystal code: elgoog/crystal_brain
- Ruby code: elgoog/ruby_brain
I executed the code with following steps.
$ crystal build examples/wave_form_standalone.cr
$ ./wave_form_standalone > /dev/null
By the way, I checked with following simple code in order to isolate the cause.
j = 0
10000000000.times do |i|
j += i
j -= 1
end
This code uses 1 core and the usage 100% correctly. However many cores are used with above crystal code of github. So, this seems to depend on the code. Is there the possibility that GC runs frequently and main program can't use CPU efficiently?