Right now MacRuby is really quite slow for string operations, I noticed it a 
while back when doing large amounts of string creation, characters swapping, 
and pushing/popping strings into/out of a priority queue.

The attached file is a string performance test and here is a run on my 15" Core 
i7 MBP with ruby 1.9.1, jruby, and MacRuby:

Name                ruby 1.9.1p378      MacRuby version     jruby 1.5.0.RC1     
--------------------------------------------------------------------------------
array:<<            0.751082            1.168693            1.290000            
array:new           0.394997            1.917601            0.277000            
array:[]            0.324454            0.755054            0.472000            
array:[]=           1.691840            0.765225            0.822000            
hash:new            1.501595            4.563549            0.444000            
hash:[]             0.612701            1.051502            0.589000            
hash:[]=            2.012367            1.135856            0.902000            
ivar:get            0.215424            0.344873            1.087000            
ivar:set            1.349466            0.243909            1.902000            
ivar:attr_writer    1.245894            4.587488            0.655000            
ivar:attr_reader    1.045779            2.755303            0.482000            
loop:upto           1.211598            5.215169            0.874000            
loop:times          1.210781            5.215054            0.876000            
loop:while          0.599330            0.157019            0.937000            
loop:for            1.442154            0.811875            1.132000            
method:args         0.728248            0.682097            1.434000            
method:noarg        0.822463            0.578383            0.837000            
method:splat        0.478610            1.805760            0.227000            
method:empty        0.807405            0.527851            1.062000            
method:opt          1.027146            2.579715            0.944000            
misc:ao_bench       7.838053            8.529954            3.248000            
misc:sudoku         1.740196            2.172581            2.461000            
misc:tak            1.277399            0.155534            1.563000            
misc:mandelbrot     2.956319            0.124588            0.854000            
misc:fib            3.827194            0.574900            4.935000            
misc:ack            1.049100            0.116299            1.217000            
proc:call+splat     0.318346            1.119665            0.191000            
proc:call+args      2.477112            1.100848            2.995000            
proc:call+noarg     2.496278            1.071953            3.507000            
string:store swap   0.153784            0.479202            0.033000            
string:<<           0.481788            143.615735          0.099000            
string:new          0.276954            1.574715            0.207000            
string:[]           0.428182            1.899233            0.072000            
string:tuple swap   0.181318            0.721778            0.045000            
yield:noarg         0.783281            0.720254            1.269000            
yield:splat         0.159219            0.965713            0.094000            
yield:less_arity    0.192418            0.843867            0.345000            
yield:same_arity    0.937823            0.763344            1.547000            
yield:more_arity    0.192516            0.848179            0.421000

Jordan

perf_test('new') do
  i = 0
  while i < 100000
    b = "#{i}"
    c = "#{i} #{i}"
    d = "#{i} #{i} #{i}"
    i += 1
  end
end

perf_test('<<') do
  i = 0
  a = ""
  while i < 100000
    a << "1"; a << "2"; a << "3"; a << "4"; a << "5"
    a << "5"; a << "4"; a << "3"; a << "2"; a << "1"
    a << "1"; a << "2"; a << "3"; a << "4"; a << "5"
    a << "5"; a << "4"; a << "3"; a << "2"; a << "1"
    i += 1
  end
end

perf_test('[]') do
  i = 0
  a = "12345"
  while i < 100000
    a[0]; a[1]; a[2]; a[3]; a[4]
    a[0]; a[1]; a[2]; a[3]; a[4]
    a[0]; a[1]; a[2]; a[3]; a[4]
    a[0]; a[1]; a[2]; a[3]; a[4]
    i += 1
  end
end

perf_test('tuple swap') do
  i = 0
  a = "12345"
  while i < 100000
    a[4], a[0] = a[0], a[4]
    a[3], a[1] = a[1], a[3]
    i += 1
  end
end

perf_test('store swap') do
  i = 0
  a = "12345"
  while i < 100000
    temp = a[0]
    a[0] = a[4]
    a[4] = temp
    temp = a[1]
    a[1] = a[3]
    a[3] = temp
    i += 1
  end
end

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to