Skip to content

Instantly share code, notes, and snippets.

View shugo's full-sized avatar

Shugo Maeda shugo

  • NaCl
  • Matsue, Shimane, Japan
View GitHub Profile
@shugo
shugo / t.rb
Created April 20, 2012 03:09
定数探索もそれっぽく動いてる #mruby
class A
X = "A::X"
Y = "A::Y"
Z = "A::Z"
end
module B
Y = "B::Y"
class C < A
@shugo
shugo / CRuby
Created April 23, 2012 00:25
new vs mutation in Ruby
$ ruby-trunk -v benchmark_new.rb
ruby 2.0.0dev (2012-04-18 trunk 35385) [i686-linux]
Rehearsal ------------------------------------------
new 1.030000 0.000000 1.030000 ( 1.035411)
color= 0.180000 0.000000 0.180000 ( 0.180050)
--------------------------------- total: 1.210000sec
user system total real
new 1.010000 0.010000 1.020000 ( 1.008668)
color= 0.180000 0.000000 0.180000 ( 0.181044)
@shugo
shugo / benchmark_parallel_fib.rb
Created April 27, 2012 01:43
@nahi JRubyだとlock-freeな方が速いようです。このベンチマークではスレッド使ってないので単純にロックのオーバーヘッドしか効いてませんが
require 'benchmark'
require 'avl_tree'
require 'red_black_tree'
require 'immutable/map'
require 'atomic'
class LockBoundFib
def initialize(map = RedBlackTree.new)
@memo = map
@shugo
shugo / t5.rb
Created August 3, 2012 04:18
@_ko1 @nagachikaさんのコードをベースに試したら1.8と同じように動いているようです
class Root
def foo
puts "Root#foo"
end
end
module M
def foo
super
puts "M#foo"
end
module M
def foo
p M
super
end
alias bar foo
end
class Base
@shugo
shugo / fizzi.rb
Created August 10, 2012 04:45
@yhara こんな感じ
module FizzBuzzInteger
refine Fixnum do
def to_s
self % 15 == 0 ? "FizzBuzz" :
self % 5 == 0 ? "Fizz" :
self % 3 == 0 ? "Buzz" :
super
end
end
end
@shugo
shugo / make.log
Created September 16, 2012 08:29
make log
CC = gcc
LD = ld
LDSHARED = gcc -shared
CFLAGS = -O0 -g -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=implicit-function-declaration -ansi -std=iso9899:199409
XCFLAGS = -include ruby/config.h -include ruby/missing.h -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE
CPPFLAGS = -I. -I.ext/include/i686-linux -I./include -I.
DLDFLAGS = -fstack-protector -pie
SOLIBS =
compiling main.c
In file included from ./include/ruby.h:33:0,
@shugo
shugo / benchmark.rb
Created September 28, 2012 09:01
benchmark for refinements
require "benchmark"
N = 1000
class Foo
def foo
end
end
class Bar
@shugo
shugo / vm_method.c.diff
Created September 28, 2012 09:14
refinement performance improvement
diff --git a/vm_method.c b/vm_method.c
index e44782c..bf02c2c 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -407,8 +407,10 @@ search_method(VALUE klass, ID id, VALUE omod, VALUE *defined_class_ptr)
iclass = rb_hash_lookup(omod, klass);
if (NIL_P(iclass) && BUILTIN_TYPE(klass) == T_ICLASS) {
iclass = rb_hash_lookup(omod, RBASIC(klass)->klass);
- if (!NIL_P(iclass))
+ if (!NIL_P(iclass)) {
@shugo
shugo / wrong protected
Created October 15, 2012 23:08
Wrong example of proteted
class Node {
def eval(other: Node): Unit = other.protected_method(this)
protected def protected_method(other: Node) = other
}
class NodeFake(node: Node) extends Node {
override def eval(other: Node): Unit = {
println("pre")
println(this == other.protected_method(this))