immutable = deeply frozen
Immutable classes
Immutable core classes
- TrueClass
- FalseClass
- NilClass
- Integer
def Process.rss | |
Integer(`ps -o rss= -p #{Process.pid}`) * 1024 | |
end | |
def mb(bytes) | |
return '?' if bytes == nil or bytes < 0 | |
mb = bytes / 1024.0 / 1024.0 | |
"#{mb.to_i} MB" | |
end |
immutable = deeply frozen
command = ARGV | |
start = Process.clock_gettime Process::CLOCK_MONOTONIC, :millisecond | |
IO.popen(command, err: [:child, :out]) do |io| | |
while line = io.gets | |
now = Process.clock_gettime Process::CLOCK_MONOTONIC, :millisecond | |
puts "[#{"%5d" % (now - start)}] #{line}" | |
end | |
end |
require 'tmpdir' | |
require 'rbconfig' | |
def inline_c_extension(c_code) | |
Dir.mktmpdir('inline_c_extension') do |dir| | |
File.write("#{dir}/cext.c", c_code) | |
File.write("#{dir}/extconf.rb", <<~RUBY) | |
require 'mkmf' | |
create_makefile('cext') | |
RUBY |
Ruby Implementation | Speedup relative to 2.7.2 |
---|---|
Ruby 2.7.2 | 1.00x |
Ruby 2.7.2 --jit | 1.16x |
Ruby 3 dev | 0.81x |
Ruby 3 dev --jit | 1.08x |
TruffleRuby CE 20.2 --jvm | 19.73x |
TruffleRuby EE 20.2 --jvm | 31.54x |
The median i/s result out of 3 is used to compute speedups.
$ ruby -ve 'puts ObjectSpace.each_object(Module).flat_map { |mod| mod.instance_methods(false).map { |name| mod.instance_method(name) }.select { |meth| meth.source_location && meth.source_location[0].start_with?("<internal:") }.map { |meth| "#{meth} #{meth.source_location.join(":")}" } }' | |
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux] | |
#<UnboundMethod: #<Class:Thread>#exclusive> <internal:prelude>:12 | |
#<UnboundMethod: IO#read_nonblock> <internal:prelude>:75 | |
#<UnboundMethod: IO#write_nonblock> <internal:prelude>:133 |
I added `x.compare!` in bin/benchmark | |
$ cd ext | |
$ rake | |
$ cd .. | |
$ gem install ffi-compiler benchmark-ips | |
$ ruby -Ilib bin/benchmark | |
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux] |
#!/usr/bin/env ruby | |
private def benchmark(name = nil, &block) | |
raise "needs a block" unless block | |
binding = block.binding | |
file, line = block.source_location | |
start_line = line - 1 | |
lines = File.readlines(file) | |
indent = lines.fetch(start_line)[/^(\s+)/, 1] |
Add Graal JIT Compilation to Your JVM Language in 5 Steps, A Tutorial http://stefan-marr.de/2015/11/add-graal-jit-compilation-to-your-jvm-language-in-5-easy-steps-step-1/
The SimpleLanguage, an example of using Truffle with great JavaDocs. It is the officle getting-started project: https://github.com/graalvm/simplelanguage
Truffle Tutorial, Christan Wimmer, PLDI 2016, 3h recording https://youtu.be/FJY96_6Y3a4 Slides
--- full.txt 2020-03-05 17:04:32.230794000 +0900 | |
+++ short.txt 2020-03-05 17:04:38.445322000 +0900 | |
@@ -1,179 +1,3 @@ | |
-1.8.5-p52 | |
-1.8.5-p113 | |
-1.8.5-p114 | |
-1.8.5-p115 | |
-1.8.5-p231 | |
-1.8.6 | |
-1.8.6-p36 |