最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

SEO心得admin82浏览0评论
本文介绍了如何知道计算在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)

发布评论

评论列表(0)

  1. 暂无评论