如何知道计算在C算法的执行时间++?

编程入门 行业动态 更新时间:2024-10-15 00:21:47
本文介绍了如何知道计算在C算法的执行时间++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要测试的数据结构是最好的看着我的算法的运行时性能,我怎么办呢?

I want to test which data structure is the best by looking at the run-time performance of my algorithm, how do I do it?

例如我已经有一个的HashMap<字符串,INT> HMP ;假设我有苹果在我的的HashMap 我想知道多久下面的语句执行的时间:麝香保心丸【苹果] 。

For example I already have a hashmap<string, int> hmp; assuming I have "apple" in my hashmap I want to know how long the following statement takes to execute: hmp["apple"].

我怎样才能几点了?

谢谢!

推荐答案

首先来看看我的回答this问题;它包含了一个便携式(的Windows / Linux)函数来获得以毫秒为单位的时间。

First of all take a look at my reply to this question; it contains a portable (windows/linux) function to get the time in milliseconds.

接下来,做这样的事情:

Next, do something like this:

int64 start_time = GetTimeMs64(); const int NUM_TIMES = 100000; /* Choose this so it takes at the very least half a minute to run */ for (int i = 0; i < NUM_TIMES; ++i) { /* Code you want to time.. */ } double milliseconds = (GetTimeMs64() - start_time) / (double)NUM_TIMES;

全部完成! (请注意,我没有试图编译)

All done! (Note that I haven't tried to compile it)

更多推荐

如何知道计算在C算法的执行时间++?

本文发布于:2023-11-30 16:17:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650657.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:执行时间   算法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!