如何获取经过的时间(以毫秒为单位)
由于 VB6 中字符串连接的性能相当弱,因此我正在测试几个 StringBuilder 实现。 为了查看它们运行了多长时间,我目前使用内置
Timer
函数,它只提供午夜后经过的秒数。
有没有办法(我想通过导入系统函数)来获得毫秒精度的东西?
Since performance of string concatenation is quite weak in VB6 I'm testing several StringBuilder implementations. To see how long they're running, I currently use the built-in
Timer
function which only gives me the number of seconds that have passed after midnight.
Is there a way (I guess by importing a system function) to get something with milliseconds precision?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
是的,您可以使用Win32 API:
要在VB6中导入它,请这样声明:
在操作之前和之后调用它,然后计算经过的时间差。
Yes, you can use the Win32 API:
To import it in VB6 declare it like this:
Call it before the operation and after and then calculate the difference in time passed.
将以下代码放入 Stopwatch 类中:
您可以按如下方式使用它:
Put the following code in a Stopwatch class:
You can use it as follows:
您也可以考虑使用不同的方法。 尝试从具有足够迭代次数的循环中调用例程,以获得可测量的时间差。
You might also consider using a different approach. Try calling your routines from a loop with enough iterations to give you a measurable time difference.
您可以使用两个 Win32 API:
它们使用 LARGE_INTEGER 来表示 64 位数字。
You can use two Win32 APIs:
These use LARGE_INTEGER to represent 64 bit numbers.
MSDN 知识库文章 Q172338 如何使用 QueryPerformanceCounter 来计时代码中提供了代码和说明
There's code and an explanation in the MSDN KB article Q172338 How To Use QueryPerformanceCounter to Time Code
有一个托马斯·爱迪生的故事,他正在面试一些未来的工程师。
他要求他们确定灯泡的体积。 考生 A 测量它,然后使用球体体积的公式和颈部体积的另一个公式,依此类推。 考生 B 将其装满水并倒入量杯中。 你认为谁得到了这份工作?
运行 1000 次,然后查看前后的手表。 秒=毫秒。
There's a Thomas Edison story, where he's interviewing some prospective engineers.
He asks them to determine the volume of a light bulb. Candidate A measures it and then uses the formula for the volume of a sphere, and another formula for the volume of the neck, and so on. Candidate B fills it with water and pours it into a measuring cup. Who do you think got the job?
Run it 1000 times and look at your watch before and after. Seconds = milliseconds.
我总是在某个模块中使用它(不过也可以在一个类中)。 此代码允许您维护最多六个计时器,并且具有高精度:
I always use this in a module somewhere (could be in a class though). This code allows you to maintain up to six timers, with high accuracy:
您可以尝试使用 System::Diagnostics::Stopwatch
You can try using the System::Diagnostics::Stopwatch