CreateThread 执行需要多长时间? [英] How long does CreateThread take to execute?

查看:58
本文介绍了CreateThread 执行需要多长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在审查创建大量线程的代码.CreateThread Windows 上的文档 说所有线程创建调用在进程内被序列化.为了估计此类代码的性能影响,我想知道 CreateThread 运行需要多长时间?我知道这取决于已经加载到进程中的 DLL 的数量,但想知道一个大概的值.

I am reviewing code which creates a lot of threads. CreateThread documentation on Windows says that a all thread creation calls are serialized within a process. To estimate the performance impact of such code, I wonder how long does CreateThread take to run? I understand this depends on the number of DLLs already loaded into the process, but would like to know a ballpark value.

谢谢!

推荐答案

最好的办法可能是编写一个单元测试,看看你的应用程序需要多长时间.

Your best bet may be to write a unit test and see how long it takes for your application.

但是,如果您需要大量线程,那么在您的程序启动时,在初始化时,您可以生成一个刚开始填充线程数组的线程,这样您就可以完成应用程序的设置线程将在需要时准备就绪.

But, if you need a large number of threads, then while your program is starting up, in the initialization, you could spawn a thread that just starts to fill in an array of threads, so you can finish setting up your application and the threads will be ready when they are needed.

如果我提供笔记本电脑的数字,它会因操作系统、处理器、内存和 .net 版本而异,因此数字充其量会非常粗略.

If I give numbers from my laptop, it will differ based on OS, processor, ram and perhaps .net version, so the numbers will be very rough at best.

这篇关于CreateThread 执行需要多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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