如何在我的 Ruby 应用程序中找到性能瓶颈? [英] How can I find the performance bottlenecks in my Ruby application?

查看:55
本文介绍了如何在我的 Ruby 应用程序中找到性能瓶颈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 Ruby 应用程序,它解析来自不同格式 html、xml 和 csv 文件的源的大量数据.如何找出代码的哪些区域耗时最长?

I have written a Ruby application which parses lots of data from sources in different formats html, xml and csv files. How can I find out what areas of the code are taking the longest?

是否有关于如何提高 Ruby 应用程序性能的好资源?或者您是否有任何一直遵循的性能编码标准?

Is there any good resources on how to improve the performance of Ruby applications? Or do you have any performance coding standards you always follow?

例如你总是用

output = String.new
output << part_one
output << part_two
output << '\n'

或者你会使用

output = "#{part_one}#{part_two}\n"

推荐答案

嗯,有一些众所周知的做法,比如字符串连接比 "#{value}" 慢得多,但为了找出脚本消耗最多的地方其时间或超过所需的时间,您需要进行分析.有一种名为 ruby​​-prof 的红宝石宝石.分析器甚至可以让您注意到那些可能很少发生的性能问题.我一直在使用它,发现它非常有帮助.以下是直接来自其官方网站

Well, there are certain well known practices like string concatenation is way slower than "#{value}" but in order to find out where you script is consuming most of its time or more time than required, you need to do profiling. There is a ruby gem called ruby-prof. The profiler can bring to your notice even those performance issues that may rarely occur. I have been using it a lot and find it very helpful. Here is some information about it directly from its official site

ruby-prof 是一个快速的代码分析器红宝石.其特点包括:

ruby-prof is a fast code profiler for Ruby. Its features include:

速度 - 它是一个 C 扩展,因此比标准 Ruby 分析器.

Speed - it is a C extension and therefore many times faster than the standard Ruby profiler.

模式 - Ruby prof 可以测量许多不同的参数,包括调用次数、内存使用和对象分配.

Modes - Ruby prof can measure a number of different parameters, including call times, memory usage and object allocations.

报告 - 可以生成文本和交叉引用的 html 报告

Reports - can generate text and cross-referenced html reports

Flat Profiles - 类似于标准 Ruby 生成的报告分析器

Flat Profiles - similar to the reports generated by the standard Ruby profiler

图形配置文件 - 类似于 GProf,它们显示方法运行的时间,哪些方法调用它,哪些它调用的方法.

Graph profiles - similar to GProf, these show how long a method runs, which methods call it and which methods it calls.

调用树配置文件 - 以调用树格式输出结果适用于 KCacheGrind 分析工具.

Call tree profiles - outputs results in the calltree format suitable for the KCacheGrind profiling tool.

线程 - 支持同时分析多个线程

Threads - supports profiling multiple threads simultaneously

递归调用 - 支持分析递归方法调用

Recursive calls - supports profiling recursive method calls

这篇关于如何在我的 Ruby 应用程序中找到性能瓶颈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆