我的bash shell需要3-4秒才能启动,而如果我启动它--norc会立即运行.
我开始"分析" /etc/bash.bashrc并~/.bashrc通过手动插入return语句和寻求速度改进,但它不是一个定量过程而且效率不高.
如何配置我的bash脚本并查看哪些命令需要花费大部分时间来启动?
什么是分析Scala方法调用的标准方法?
我需要的是一个方法的钩子,我可以使用它来启动和停止计时器.
在Java中,我使用方面编程aspectJ来定义要分析的方法并注入字节码以实现相同的目的.
在Scala中是否有更自然的方式,我可以在函数前后定义一组函数,而不会在进程中丢失任何静态类型?
我想知道某个函数在我的C++程序中执行多长时间才能在Linux上执行.之后,我想进行速度比较.我看到了几个时间功能,但结果来自于boost.计时:
process_user_cpu_clock, captures user-CPU time spent by the current process
Run Code Online (Sandbox Code Playgroud)
现在,我不清楚我是否使用上述功能,我将获得CPU花在该功能上的唯一时间吗?
其次,我找不到任何使用上述功能的例子.任何人都可以帮我如何使用上述功能?
PS:现在,我std::chrono::system_clock::now()用来在几秒钟内获得时间,但由于每次CPU负载不同,这给了我不同的结果.
经常这样我发现自己对小块代码进行基准测试,看看哪个实现最快.
我经常看到基准测试代码没有考虑到jitting或垃圾收集器的评论.
我有以下简单的基准测试功能,我已经慢慢演变了:
static void Profile(string description, int iterations, Action func) {
// warm up
func();
// clean up
GC.Collect();
var watch = new Stopwatch();
watch.Start();
for (int i = 0; i < iterations; i++) {
func();
}
watch.Stop();
Console.Write(description);
Console.WriteLine(" Time Elapsed {0} ms", watch.ElapsedMilliseconds);
}
Run Code Online (Sandbox Code Playgroud)
用法:
Profile("a descriptions", how_many_iterations_to_run, () =>
{
// ... code being profiled
});
Run Code Online (Sandbox Code Playgroud)
这个实现是否有任何缺陷?是否足以表明实现X比Z迭代实现Y更快?您能想出任何可以改善这种情况的方法吗?
编辑 很明显,基于时间的方法(与迭代相反)是首选,是否有人有任何实施时间检查不会影响性能?
我一直在使用cProfile来分析我的代码,它一直很好用.我还使用gprof2dot.py来显示结果(使其更清晰).
但是,cProfile(以及到目前为止我见过的大多数其他Python分析器)似乎只在函数调用级别进行分析.当从不同的地方调用某些函数时,这会引起混淆 - 我不知道呼叫#1或呼叫#2是否占用了大部分时间.当所讨论的函数深度为六级时,这会变得更糟,从其他七个地方调用.
如何进行逐行分析?
而不是这个:
function #12, total time: 2.0s
Run Code Online (Sandbox Code Playgroud)
我想看到这样的事情:
function #12 (called from somefile.py:102) 0.5s
function #12 (called from main.py:12) 1.5s
Run Code Online (Sandbox Code Playgroud)
cProfile确实显示了总共有多少时间"转移"到父级,但是当你有一堆层和互连的调用时,这种连接又会丢失.
理想情况下,我希望有一个GUI来解析数据,然后向我显示我的源文件,每个行的总时间.像这样的东西:
main.py:
a = 1 # 0.0s
result = func(a) # 0.4s
c = 1000 # 0.0s
result = func(c) # 5.0s
Run Code Online (Sandbox Code Playgroud)
然后我就可以点击第二个"func(c)"调用来查看该调用中占用的时间,与"func(a)"调用分开.
那有意义吗?是否有任何分析库收集此类信息?我错过了一些很棒的工具吗?
据我所知,有很多方法可以在jQuery中选择子元素.
//Store parent in a variable
var $parent = $("#parent");
Run Code Online (Sandbox Code Playgroud)
方法1 (使用范围)
$(".child", $parent).show();
Run Code Online (Sandbox Code Playgroud)
方法2 (find()方法)
$parent.find(".child").show();
Run Code Online (Sandbox Code Playgroud)
方法3 (仅限直系儿童)
$parent.children(".child").show();
Run Code Online (Sandbox Code Playgroud)
方法4 (通过CSS选择器) - 由@spinon建议
$("#parent > .child").show();
Run Code Online (Sandbox Code Playgroud)
方法5 (与方法2相同) - 根据@Kai
$("#parent .child").show();
Run Code Online (Sandbox Code Playgroud)
我不熟悉分析能够自己调查这个,所以我很想知道你要说些什么.
PS我明白这可能是这个问题的重复,但并不涵盖所有方法.
在解决一些项目Euler问题以学习Haskell(所以目前我是一个完全初学者)时,我遇到了问题12.我写了这个(天真的)解决方案:
--Get Number of Divisors of n
numDivs :: Integer -> Integer
numDivs n = toInteger $ length [ x | x<-[2.. ((n `quot` 2)+1)], n `rem` x == 0] + 2
--Generate a List of Triangular Values
triaList :: [Integer]
triaList = [foldr (+) 0 [1..n] | n <- [1..]]
--The same recursive
triaList2 = go 0 1
where go cs n = (cs+n):go (cs+n) (n+1)
--Finds the first triangular Value with more than n Divisors
sol …Run Code Online (Sandbox Code Playgroud) 谁能告诉我你用于分析的工具,比如kcachegrind wingrind valgrind for mac platform.
我不认为这些工作在Mac上,我也快速检查.
我的django应用程序在生产中变得非常缓慢.可能是由于一些复杂或无索引的查询.
是否有任何django-ish方式来描述我的应用程序?
我需要找到Android应用中瓶颈的位置.
我可以使用哪些分析工具或技术?