Add support for bundle gem --ext=rust command.
Cool to see support for writing extension gems in Rust shipping with Ruby. class Foo
def foo=(object)
puts "foo= called with #{object.inspect}"
@foo = object
end
def foo
puts "foo called"
@foo
end
end
puts "x || x = y"
a = Foo.new
a.foo || a.foo = 1
a.foo || a.foo = 2
puts "\nx = x || y"
b = Foo.new
b.foo = b.foo || 1
b.foo = b.foo || 2
puts "\nx ||= y"
c = Foo.new
c.foo ||= 1
c.foo ||= 2
This outputs: x || x = y
foo called
foo= called with 1
foo called
x = x || y
foo called
foo= called with 1
foo called
foo= called with 1
x ||= y
foo called
foo= called with 1
foo called
and you can see that the output for ||= matches the output for x || x = y require "benchmark"
n = 100_000
Benchmark.bm(4) do |x|
x.report("<<") do
n.times do
"aaaaa " << "bbbbbb " << "ccccc " << "ddddd " << "eeeee " << "fffff"
end
end
x.report("join") do
n.times do
["aaaaa", "bbbbbb", "ccccc", "ddddd", "eeeee", "fffff"].join(" ")
end
end
end
The results I get for this are: user system total real
<< 0.140000 0.000000 0.140000 ( 0.143750)
join 0.230000 0.000000 0.230000 ( 0.228035)
I'd be interested to see if there were any use cases where the relative performance was reversed.
After implementing and benchmarking it I found my code was spending more time calculating the sample points than I'd like. When trying to speed that up I found this paper: https://www.sciencedirect.com/science/article/pii/0898122193...
Later when learning Rust I ported that faster approach to Rust: https://crates.io/crates/halton
And when I wrote a Rust library to bind Rust to Ruby, I created a Rubygem of the same as a testbed: https://rubygems.org/gems/halton
A few years ago I also put together a fun D&D game using the Halton sequence to place items/encounters on a map.