CPU成本数量级对于一些基本操作 [英] CPU cost order of magnitude for some basic operations

查看:128
本文介绍了CPU成本数量级对于一些基本操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回答 SO问题和被告知我想和你检查一些东西。

After answering to that SO question and being donwvoted I'd like to check something with you.

为了有一个想法代码的代价我写的我的倾向

So as to have a draft idea of the cost of the code I write, I have the tendency to scale operations this way.


  • 堆分配比堆栈分配慢1000倍。

  • 屏幕/输出的IO大约是1000倍
    比堆分配慢。

  • 硬盘上的IO比屏幕上的图形IO慢
    约1000倍。

你认为这是正确的假设/数量级/估计吗?

Do you think this is correct assumption / order of magnitude / estimation ?

(当然,没有什么像应用程序的真实概要:-))

(And of course, there is nothing like a real profiling of the application :-))

编辑:作为根据您的回答和评论的第一个结论,可以说我的图1000被大大高估了。

as a first conclusion according to your answers and comment, one may say that my figure 1000 is largely overestimated.

推荐答案

第一点取决于很多事情,真的。如果你的内存不足,那么在堆上分配东西可能需要几分钟。另一方面,堆栈可能已在此时分配。

The 1st point depends on a lot of things, really. If you run out of memory, then allocating something on the heap may take literally minutes. The stack, on the other hand, may already be allocated at that point.

第二点取决于所使用的终端。输出到DOS屏幕是一回事,输出到Windows控制台窗口是另一个,和xterm是完全不同于他们。

The 2nd point depends on the terminal being used. Outputting to a DOS screen is one thing, outputting to a Windows console window is another, and xterm is something entirely different from them too.

至于第三点,我而是说现代硬盘的另一种方式。他们可以轻松地处理每秒的兆字节,你怎么能想象在这么短的时间内输出到任何终端?对于少量的数据,你可能是正确的,因为硬盘I / O可能需要一些时间来准备。

As for the 3rd point, I'd rather say it's the other way around for modern hard disks. They can easily handle megs per second, how can you imagine outputting that much to any terminal in such short time? For small amounts of data you may be right, though, as hard drive I/O may take some time to prepare.

这篇关于CPU成本数量级对于一些基本操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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