Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rubinius vs. CRuby

Rubinius vs. CRuby

Comparison between Rubinius and CRuby held at LRUG 12 om 2014/12/18

Avatar for CucumisSativus

CucumisSativus

December 18, 2014

More Decks by CucumisSativus

Other Decks in Technology

Transcript

  1. What is Rubinius? • Interpreter + ruby virtual machine based

    on LLVM • Written mostly in ruby • Has C-API for running C extensions • Implementation of Ruby which uses native threads
  2. Parser stage • calls Melbourne parser, the same as in

    CRuby • using ruby code, creates AST trees
  3. Abstract Syntax Trees • Trees created to execute program in

    proper order • Created recursively up the the level of primitives
  4. Generator Stage • Generates byte code from an AST •

    Creates main Generator object and child Generators for block, methods etc. • Maps directly to Rubinius Instructions like push_int(number), goto_if_true(location) etc.
  5. Encoder Stage • Creates instruction sequence - all instructions are

    put in proper place • Validates stack for underflow, overflow and so on
  6. Packager Stage • During this stage Rubinius creates CompiledCode object

    • CompiledCode is an ruby object, which contains byte code created during encoder stage, variable count, variable names, arguments etc.
  7. Writer Stage • writes method to file for future use

    • creates CompiledFile ruby object • returns input
  8. Conclusion • Rubinius has modular structure • Every phase can

    be customized • Which can be done much easier thanks to modular structure
  9. bm_count_multithreaded.rb def count_high 100_000.times {} end Bench.run [1, 2, 4,

    8, 16] do |n| threads = [] n.times{ threads << Thread.new { count_high }} threads.each{|t| t.join} end
  10. bm_count_shared_thread.rb def count_high how_many how_many.times {} end Bench.run [1, 2,

    4, 8, 16] do |n| threads = [] n.times{ threads << Thread.new { count_high(1_000_000 / n) }} threads.each{|t| t.join} end
  11. bm_hilbert_matrix.rb def hilbert(dimension) rows = Array.new (1..dimension).each do |i| row

    = Array.new (1..dimension).each do |j| row.push(1/(i + j - 1)) end rows.push(row) end return(Matrix.rows(rows)) end Hilbert Matrix of size 5
  12. bm_dirp.rb Bench.run [10000] do |n| n.times do dirp = Dir.open(".")

    for f in dirp case f when /^\./, /~$/, /\.o/ # do not print else # don't print since we don't care about print speed #print f, "\n" end end dirp.close end end
  13. bm_so_lists.rb def test_lists(size) li1 = (1..size).to_a li2 = li1.dup li3

    = Array.new while (not li2.empty?) li3.push(li2.shift) end while (not li3.empty?) li2.push(li3.pop) end li1.reverse! if li1[0] != size then p "not size" 0 else if li1 != li2 then return(0) else li1.length end end end
  14. bm_gc_mb.rb Bench.run [500_000, 1_000_000, 3_000_000] do |n| a = []

    n.times { a << []} # use up some RAM n.times {[]} end