Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

prepped for release

[git-p4: depot-paths = "//src/zenprofile/dev/": change = 4959]
  • Loading branch information...
commit e71d3ca9d96cb71d18b01f6bb6de7529f28fd05d 1 parent f7adbcb
@zenspider zenspider authored
Showing with 66 additions and 15 deletions.
  1. +45 −7 README.txt
  2. +5 −1 Rakefile
  3. +5 −1 misc/factorial.rb
  4. +11 −6 zenprofile-demo.sh
View
52 README.txt
@@ -1,32 +1,70 @@
= zenprofile
-* FIX (url)
+* http://rubyforge.org/projects/seattlerb
== DESCRIPTION:
-FIX (describe your package)
+zenprofiler helps answer WHAT is being called the most. spy_on helps
+answer WHERE those calls are being made. ZenProfiler provides a faster
+version of the standard library ruby profiler. It is otherwise pretty
+much the same as before. spy_on provides a clean way to redefine a
+bottleneck method so you can account for and aggregate all the calls
+to it.
+
+ % ruby -Ilib bin/zenprofile misc/factorial.rb 50000
+ Total time = 3.056884
+ Total time = 2.390000
+
+ total self self total
+ % time seconds seconds calls ms/call ms/call name
+ 50.70 1.64 1.64 50000 0.03 0.05 Integer#downto
+ 19.63 2.27 0.63 200000 0.00 0.00 Fixnum#*
+ 14.19 2.73 0.46 50000 0.01 0.05 Factorial#factorial
+ 9.93 3.05 0.32 1 320.36 3047.10 Range#each
+ 5.54 3.23 0.18 2 89.40 178.79 ZenProfiler#start_hook
+
+Once you know that Integer#downto takes 50% of the entire run, you
+can use spy_on to find it. (See misc/factorial.rb for the actual code):
+
+ % SPY=1 ruby -Ilib misc/factorial.rb 50000
+ Spying on Integer#downto
+
+ Integer.downto
+
+ 50000: total
+ 50000: ./misc/factorial.rb:6:in `factorial' via
+ ./misc/factorial.rb:6:in `factorial'
== FEATURES/PROBLEMS:
-* FIX (list of features or problems)
+* 4x faster than stdlib ruby profiler by using event_hook to bypass set_trace_func
+* 1/14th the amount of code of ruby-prof. Much easier to play with.
== SYNOPSIS:
- FIX (code sample of usage)
+ % zenprofile [ruby-flags] misc/factorial.rb
+
+then:
+
+ Array.spy_on :select, :each
+
+run your code, then you'll see where the calls to Array#select and
+#each are coming from.
== REQUIREMENTS:
-* FIX (list of requirements)
+* event_hook
+* RubyInline
== INSTALL:
-* FIX (sudo gem install, anything else)
+* sudo gem install zenprofile
== LICENSE:
(The MIT License)
-Copyright (c) 2008 FIX
+Copyright (c) 2009 Ryan Davis, seattle.rb
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
6 Rakefile
@@ -2,11 +2,15 @@
require 'rubygems'
require 'hoe'
-require './lib/zenprofile.rb'
+require './lib/zenprofiler.rb'
Hoe.new('zenprofile', ZenProfiler::VERSION) do |p|
p.rubyforge_name = 'seattlerb'
p.developer('Ryan Davis', 'ryand-ruby@zenspider.com')
+
+ p.extra_deps << 'ZenTest'
+ p.extra_deps << 'event_hook'
+ p.extra_deps << 'RubyInline'
end
# vim: syntax=Ruby
View
6 misc/factorial.rb
@@ -1,13 +1,17 @@
#!/usr/local/bin/ruby -w
class Factorial
-
def factorial(n)
f = 1
n.downto(2) { |x| f *= x }
return f
end
+end
+
+if ENV['SPY'] then
+ require 'spy_on'
+ Integer.spy_on :downto
end
if $0 == __FILE__ then
View
17 zenprofile-demo.sh
@@ -2,7 +2,7 @@
N=$1
-if [ -z $N ]; then N=5000; fi
+if [ -z $N ]; then N=100_000; fi
if [ -z $2 ]; then SKIP=no; else SKIP=yes; fi
rm -rf ~/.ruby_inline
@@ -12,18 +12,23 @@ echo N=$N
if [ $SKIP = no ]; then
echo
- echo ruby vanilla:
- time ruby misc/factorial.rb $N
+ echo ruby vanilla :
+ X=1 time ruby misc/factorial.rb $N
echo
echo ruby profiler:
- time ruby -rprofile misc/factorial.rb $N 2>&1 | head -6
+ X=1 time ruby -rprofile misc/factorial.rb $N 2>&1 | egrep -v "^ *0.00"
fi
echo
-echo zenspider profiler:
+echo zen profiler :
export GEM_SKIP=RubyInline
-time ./bin/zenprofile misc/factorial.rb $N 2>&1 | head -9
+X=1 time ./bin/zenprofile misc/factorial.rb $N 2>&1 | egrep -v "^ *0.00"
+
+echo
+echo zen profiler pure ruby:
+export GEM_SKIP=RubyInline
+PURERUBY=1 time ./bin/zenprofile misc/factorial.rb $N 2>&1 | egrep -v "^ *0.00"
# shugo's version
# time ruby -I.:lib -runprof misc/factorial.rb $N 2>&1 | head
Please sign in to comment.
Something went wrong with that request. Please try again.