Created
February 22, 2013 10:33
-
-
Save octplane/5012452 to your computer and use it in GitHub Desktop.
Stress Test V8 to exhibit memory usage. Uncomment line 5 to demonstrate that SetFlagsFromString has actual impact on the V8 runtime.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'handlebars' | |
require 'v8' | |
# V8::C::V8.SetFlagsFromString("--max-old-space-size=200") | |
@heap_stats_methods = [:total_heap_size, :total_heap_size_executable, :used_heap_size, :heap_size_limit] | |
@st = V8::C::HeapStatistics.new | |
def dump_stats | |
V8::C::V8.GetHeapStatistics(@st) | |
@heap_stats_methods.each do |m| | |
v = @st.send(m)/1_000_000 | |
puts "#{m} : #{"%05.2f" % v}MB" | |
end | |
end | |
puts "starting up" | |
c = Handlebars::Context.new | |
1.upto(100) do |i| | |
t = "pouet#{i} {{gna}} "+"this is a dummy text."*1_000 | |
d = {gna: "chlu"} | |
c.compile(t*1_000).call(d) | |
if i % 10 == 0 | |
print "." | |
$stdout.flush | |
end | |
if i % 10 == 1 | |
puts "At #{i}" | |
dump_stats | |
GC.start() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment