ruby-prof

来源:互联网 发布:集体智慧编程 pdf 编辑:程序博客网 时间:2024/06/08 15:24

ruby-prof

ruby-prof是比较强大的,支持cpu,内存使用,对象分配等等的性能分析,而且提供了很多友好的输出格式,不仅仅是有基于文字,html的格式,还能输出graphviz格式的dot文件。

require 'ruby-prof'RubyProf.start# 这里写入要进行性能剖析的代码result = RubyProf.stop# 选择一个Printerprinter = RubyProf::FlatPrinter.new(result)printer.print(STDOUT)
#代码示例require 'ruby-prof'def perf_test  if params[:__t]    RubyProf.start    yield    result = RubyProf.stop    printer = RubyProf::GraphPrinter.new(result)    printer  else    yield  endenddef hi  100_000.times { }enddef hello  10_000.times { }endRubyProf.starthihelloresult = RubyProf.stopprinter = RubyProf::GraphPrinter.new(result)printer.print(STDOUT, {})

这里写图片描述

这里写图片描述

参考链接 https://ruby-china.org/topics/25959

GitHub链接 https://github.com/ruby-prof/ruby-prof

原创粉丝点击