rubinius

Performance difference between MRI Ruby and jRuby

怎甘沉沦 提交于 2019-12-23 10:44:02
问题 While doing some benchmarking to answer this question about the fastest way to concatenate arrays I was surprised that when I did the same benchmarks in with jRuby the tests were a lot slower. Does this mean that the old adagio about jRuby being faster than MRI Ruby is gone ? Or is this about how arrays are treated in jRuby ? Here the benchmark and the results in both MRI Ruby 2.3.0 and jRuby 9.1.2.0 Both run on a 64bit Windows 7 box, all 4 processors busy for 50-60%, memory in use ± 5.5GB.

Performance difference between MRI Ruby and jRuby

折月煮酒 提交于 2019-12-23 10:43:13
问题 While doing some benchmarking to answer this question about the fastest way to concatenate arrays I was surprised that when I did the same benchmarks in with jRuby the tests were a lot slower. Does this mean that the old adagio about jRuby being faster than MRI Ruby is gone ? Or is this about how arrays are treated in jRuby ? Here the benchmark and the results in both MRI Ruby 2.3.0 and jRuby 9.1.2.0 Both run on a 64bit Windows 7 box, all 4 processors busy for 50-60%, memory in use ± 5.5GB.

“\xC2” to UTF-8 in conversion from ASCII-8BIT to UTF-8

本小妞迷上赌 提交于 2019-12-12 12:09:24
问题 I have a rails project that runs fine with MRI 1.9.3. When I try to run with Rubinius I get this error in app/views/layouts/application.html.haml : "\xC2" to UTF-8 in conversion from ASCII-8BIT to UTF-8 回答1: It turns out the page had an invalid character (an interpunct '·'), which I found out with the following code (credits to this gist and this question): lines = IO.readlines("app/views/layouts/application.html.haml").map do |line| line.force_encoding('ASCII-8BIT').encode('UTF-8', :invalid

How do you write a compiler for a language in that language? [duplicate]

浪尽此生 提交于 2019-12-12 09:34:43
问题 This question already has answers here : Closed 9 years ago . Possible Duplicates: How can a language's compiler be written in that language? implementing a compiler in “itself” I was looking at Rubinius, a Ruby implementation that compiles to bytecode using a compiler written in Ruby. I cannot get my head around this. How do you write a compiler for a language in the language itself? It seems like it would be just text without anything to compile it into an executable that could then compile

Cross-Implementation Deterministic Array#shuffle

≯℡__Kan透↙ 提交于 2019-12-08 02:56:19
问题 It is possible to pass a random number generator to Array#shuffle that makes the shuffle deterministic. For example, in MRI 1.9.3p327: [1, 2, 3, 4].shuffle(random: Random.new(0)) # => [1, 2, 4, 3] [1, 2, 3, 4].shuffle(random: Random.new(0)) # => [1, 2, 4, 3] However, the random number generator implementation of Random isn't specified. Because of this, other implementations of Ruby have different results. In Rubinius 2.0.0rc1 (1.9.3 release 2012-11-02 JI): [1, 2, 3, 4].shuffle(random: Random

Where are mixins implemented in Rubinius?

社会主义新天地 提交于 2019-12-07 18:14:31
问题 Where in the Rubinius source is the code that is responsible for including modules?(Specifically, to place module as super class of object class.) 回答1: If you look at the documentation for Module#include, you’ll find that it delegates to Module#append_features : Invokes Module.append_features on each parameter in reverse order. The documentation for Module#append_features, in turn, describes (very briefly) how the default Ruby mixin algorithm works: When this module is included in another,

Cross-Implementation Deterministic Array#shuffle

我的未来我决定 提交于 2019-12-06 08:36:27
It is possible to pass a random number generator to Array#shuffle that makes the shuffle deterministic. For example, in MRI 1.9.3p327: [1, 2, 3, 4].shuffle(random: Random.new(0)) # => [1, 2, 4, 3] [1, 2, 3, 4].shuffle(random: Random.new(0)) # => [1, 2, 4, 3] However, the random number generator implementation of Random isn't specified. Because of this, other implementations of Ruby have different results. In Rubinius 2.0.0rc1 (1.9.3 release 2012-11-02 JI): [1, 2, 3, 4].shuffle(random: Random.new(0)) # => [1, 3, 2, 4] [1, 2, 3, 4].shuffle(random: Random.new(0)) # => [1, 3, 2, 4] Incidentally,

How can I redefine Fixnum's + (plus) method in Ruby and keep original + functionality?

血红的双手。 提交于 2019-11-27 16:38:18
问题 This throws me a SystemStackError in 1.9.2 Ruby ( but works in Rubinius ): class Fixnum def +(other) self + other * 2 end end but there is no super for + (based on other errors). How can I access the original + functionality? 回答1: Use alias_method . Alias Fixnum 's + to something else, then refer to it in the new + : class Fixnum alias_method :old_add, :+ def +(other) self.old_add(other) * 2 end end 回答2: Another interesting approach would be to pass a block to Fixnum's module_eval method. So,