我在剖析中是个假人,请告诉我你的人如何分析你的申请.哪一个更好,分析整个应用程序或隔离?如果选择是隔离你如何做到这一点?
我有一个Ruby程序,大约需要4分钟才能完成任务,我想把它降到1分钟以下.
我尝试了宝石中的ruby-prof,但是它使运行时间增加到约30分钟,甚至看起来都没有特别好地保持单调性(一些变化可靠地提高了性能 - 使用剖析器并且可靠地降低了性能 - 没有剖析器).此任务也无法真正分解为可以独立进行有意义分析的部分.
目前以最低开销分析Ruby代码的最佳方法是什么?
我使用OSX,但如果由于任何原因,探测器需要另一个操作系统,我可能会重新启动.
编辑:perftools.rb具有更低的开销,但结果看起来相当可疑诚实,超出任何合理的抽样错误 - 至少它必须搞乱GC或i/o缓冲或类似的东西,导致很多愚蠢的错误归因.它仍然击败了ruby-prof.
我会保持问题公开,万一有人知道比这更好的事情.
我可以使用哪些免费工具来测试Linux中C++代码的性能?基本上我想确定代码的瓶颈并提高性能.我的应用程序主要涉及使用来自网络的数据的计算代码.所以我想提高代码的执行速度.
谢谢.
我知道应该在静态环境中访问睡眠.但是我需要更多的输入,所以我可以向管理层辩护.我正在处理的大多数遗留代码现在使用新的Thread().sleep而不是Thread.sleep.
这有多糟糕?
for (int c = 0; c < 5; c++) {
new Thread().sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)
与此相比?
for (int c = 0; c < 5; c++) {
Thread.sleep(5000);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
final long start = System.currentTimeMillis();
System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());
System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());
System.out.println("===========================");
for (int c = 0; c < 5; c++) {
new Thread().sleep(5000);
System.out.println("Used memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
System.out.println("===========================");
}
System.out.println("Total memory: " + Runtime.getRuntime().totalMemory());
System.out.println("Free memory: " + Runtime.getRuntime().freeMemory());
System.out.println("===========================");
System.out.println("Time elapsed: " …Run Code Online (Sandbox Code Playgroud) 您是否知道如何使此功能更加节省时间?
def c(n):
word = 32
#l = []
c = 0
for i in range(0, 2**word):
#print(str(bin(i)))#.count('1')
if str(bin(i)).count('1') == n:
c = c + 1
print(c)
if i == 2**28:
print('6 %')
if i == 2**29:
print('12 %')
if i == 2**30:
print('25 %')
if i == 2**31:
print('50 %')
if i == 2**32:
print('100 %')
return c
135274023 function calls in 742.161 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 391.662 391.662 742.161 …Run Code Online (Sandbox Code Playgroud) 使用两者来分析一些C++数字运算代码,gprof并kcachegrind为对执行时间贡献最大的函数(取决于输入的50-80%)给出类似的结果,但对于10-30%之间的函数,这些工具都给出不同的结果.这是否意味着其中一个不可靠?你会怎么做?
我使用gprof和报告来描述我的代码,大多数,如果不是所有前20个左右的东西都是关于向量的
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
14.71 0.05 0.05 3870399 0.00 0.00 std::vector<bool, std::allocator<bool> >::size() const
11.76 0.09 0.04 10552897 0.00 0.00 std::_Bit_reference::_Bit_reference(unsigned long*, unsigned long)
11.76 0.13 0.04 7890323 0.00 0.00 std::_Bit_const_iterator::_Bit_const_iterator(std::_Bit_iterator const&)
5.88 0.15 0.02 10089215 0.00 0.00 std::_Bit_iterator::operator*() const
5.88 0.17 0.02 6083600 0.00 0.00 std::vector<bool, std::allocator<bool> >::operator[](unsigned int)
5.88 0.19 0.02 3912611 0.00 0.00 std::vector<bool, std::allocator<bool> >::end() const
5.88 0.21 0.02 …Run Code Online (Sandbox Code Playgroud) 与同事讨论的结果我最终编写了测试std::vectorvs原始动态分配数组的基准测试,结果出人意料.
我的测试如下:
#include "testconsts.h" // defines NUM_INTS across all tests
#include <vector>
int main()
{
const int numInts = NUM_INTS;
std::vector<int> intVector( numInts );
int * const intArray = new int[ numInts ];
++intVector[0]; // force access to affect optimization
++intArray[0]; // force access to affect optimization
for( int i = 0; i < numInts; ++i )
{
++intArray[i];
}
delete[] intArray;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
和:
#include "testconsts.h" // defines NUM_INTS across all tests
#include <vector>
int main() …Run Code Online (Sandbox Code Playgroud) 我有一个页面请求,需要超过12秒来呈现.我使用newrelic lite来跟踪这个应用程序的性能,但在我的情况下,它不是很有用.它只显示一行:
PagesController#index 0.001 13,030 13030
Run Code Online (Sandbox Code Playgroud)
所以,不是很有用.:)我记得使用的工具我觉得ruby-prof哪个好.您提供了类似于?profiler=true请求的内容,它为您提供了方法调用时间花费的所有详细信息(不在浏览器中显示实际页面).不幸的是,我还没有找到它.
有任何想法,每个请求/页面有一个更详细的探查器?
使用:Ruby 1.9.2,Rails 3.1.1,RSpec,New Relic RPM 3.3.0,Mongoid 2.3.3
几年后我再次与IDEA合作,到目前为止我很开心.问题只是奇怪的内存使用行为和GC操作,而我正在处理的项目导致我的IDE冻结几秒钟,而GC正在完成它的工作.无论项目有多大,我都在努力,几天之后内存使用量增加到500 MB(我的堆空间最大512 MB,实际上,我认为,它必须足够用于拥有大约100个java的Web项目文件).在GC完成它的工作之后,我得到了400 MB的使用 - 没有收集 - 并且只有大约100 MB的堆免费,并且在几分钟内内存使用量增加了堆再次满了.
JVM version is 19.0-b09
using thread-local object allocation.
Parallel GC with 2 thread(s)
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 536870912 (512.0MB)
NewSize = 178257920 (170.0MB)
MaxNewSize = 178257920 (170.0MB)
OldSize = 4194304 (4.0MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 16777216 (16.0MB)
MaxPermSize = 314572800 (300.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 145489920 (138.75MB)
used = 81242600 (77.4789810180664MB)
free = 64247320 (61.271018981933594MB)
55.84070704004786% …Run Code Online (Sandbox Code Playgroud)