Skip to content

Instantly share code, notes, and snippets.

View brixen's full-sized avatar

Brian Shirai brixen

View GitHub Profile
@pd
pd / 00-symbol-vs-string-equality.rb
Created January 27, 2015 00:52
rbx -v == rubinius 2.5.0.n24 (2.1.0 af7eb1b4 2015-01-24 3.5.0 JI) [x86_64-darwin14.0.0]
require 'benchmark/ips'
SYM = :magic_key
MYS = :key_magic
STR = 'magic_key'
RTS = 'key_magic'
Benchmark.ips do |x|
x.config(time: 2, warmup: 1)
@sshao
sshao / points.md
Last active August 29, 2015 14:14
writing a language on the rbx vm
  • Identifying and explaining general concepts
    • scopes, bindings, environments
    • the background context behind 'running' a file/script/method
  • Compiler stages:
    • how they're organized and how they're chained
    • how to define the first/last stages. Does the first stage have to be the parser? (I tried to implement a 'lexer' stage before then, and couldn't figure out how)
  • Initializing the environment (things like initializing heap size/space) before compilation or execution
  • A high-level overview of how code -> s-expressions -> AST/AST nodes -> bytecode
*.rbc
*.pyc
# Original blog post about Rubinius performance on the alioth mandelbrot benchmark:
# http://rfc2616.wordpress.com/2010/10/16/rubinius-vs-the-benchmark-from-hell/
#
# Problems with assumptions in the blog post:
# * The C <-> Ruby comparison is apples to oranges because the Ruby code
# is written to use blocks rather than loops. That imposes the overhead
# of additional execution contexts per pixel.
# * The output is written a byte at a time, which requires a fairly deep
# chain of methods before the byte is handed off to the OS.
# * The work is done in the script body. Unless the implementation has
def stat(args)
p :stat => args
end
def xtest(number)
p "number is: #{number}"
return false if number == 3
return true
end
require "benchmark"
N = (ARGV.shift || 40).to_i
def fib(n)
return n if n < 2
fib(n-2) + fib(n-1)
end
Benchmark.bmbm do |x|
# eager loading
$ bin/rbx -Xint -r rubinius/analyst -e 'puts Rubinius::Analyst.new.itemized_memory'
Young: 6.0M
Mature: 10.0M
Large: 751.7K
Code: 2.9M
Symbols: 89.6K
Total: 19.7M
@headius
headius / gist:961054
Created May 8, 2011 02:41
invokedynamic example in BiteScript
import java.lang.invoke.MethodHandle
import java.lang.invoke.MethodType
import java.lang.invoke.CallSite
import java.lang.invoke.ConstantCallSite
import java.lang.invoke.MethodHandles::Lookup
JClass = java.lang.Class
# Our main method, which does one invokedynamic
main do
# handle for our bootstrap, which binds invokedynamic to a CallSite
sasha:rubinius2.0 brian$ rbx
irb(main):001:0> o = Object.new
=> #<Object:0xf30>
irb(main):002:0> sc = Rubinius::Type.object_singleton_class(o)
=> #<Class: #<Object:3888>>
irb(main):003:0> module N
irb(main):004:1> def foo; puts 'foozee'; end
irb(main):005:1> end
=> #<Rubinius::CompiledMethod foo file=(irb)>
irb(main):007:0> sc.send :include,