-
Notifications
You must be signed in to change notification settings - Fork 0
/
breakdown.rb
executable file
·63 lines (62 loc) · 2.12 KB
/
breakdown.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
require 'rubygems'
require 'benchmark'
require 'multiarray'
include Hornetseye
# ruby1.9 breakdown.rb
N = 1_000_000
Benchmark.bm(32) do |x|
c = 1000
s = Sequence.ubyte N
-s
GC.start
x.report( 'Ruby' ) do
c.times { -s }
GC.start
end
class Seq
attr_reader :memory, :size
def initialize(size)
@memory = Malloc.new size
@size = size
end
def inspect
Sequence.import(UBYTE, @memory, @size).inspect
end
def -@
retval = Seq.new @size
GCCCache._Store0Lambda0Variable60INDEX0Variable20INT1112Lookup0Variable0050UBYTE112Variable60INDEX0Variable20INT1112Variable10INT1112490Lambda0Variable60INDEX0Variable50INT1112Lookup0Variable3050UBYTE112Variable60INDEX0Variable50INT1112Variable40INT11111 retval.memory, 1, retval.size, @memory, 1, @size
retval
end
end
s = Seq.new N
GC.start
x.report( 'optimised Ruby code' ) do
c.times { -s }
GC.start
end
system 'cp breakdown.c /tmp/hornetseye-ruby1.9.2-jan/breakdown.c'
system 'gcc -shared -DNDEBUG -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -fPIC -I/usr/local/include/ruby-1.9.1 -I/usr/local/include/ruby-1.9.1/x86_64-linux -o /tmp/hornetseye-ruby1.9.2-jan/breakdown.so /tmp/hornetseye-ruby1.9.2-jan/breakdown.c -L/usr/local/lib -Wl,-R -Wl,/usr/local/lib -L/usr/local/lib -lruby -L. -rdynamic -Wl,-export-dynamic'
require '/tmp/hornetseye-ruby1.9.2-jan/breakdown.so'
GC.start
x.report( 'optimised Ruby and C code' ) do
c.times { -s }
GC.start
end
GC.start
x.report( 'allocation only' ) do
c.times { Seq.new N }
GC.start
end
$retval = Seq.new N
class Seq
def -@
GCCCache._Store0Lambda0Variable60INDEX0Variable20INT1112Lookup0Variable0050UBYTE112Variable60INDEX0Variable20INT1112Variable10INT1112490Lambda0Variable60INDEX0Variable50INT1112Lookup0Variable3050UBYTE112Variable60INDEX0Variable50INT1112Variable40INT11111 $retval.memory, 1, $retval.size, @memory, 1, @size
$retval
end
end
x.report( 'static memory layout' ) do
c.times { -s }
GC.start
end
end