计算哈希插入的运行时间? [英] Calculating the runtime of a hash insertion?

查看:168
本文介绍了计算哈希插入的运行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算哈希插入的运行时。我一直在使用时钟做的时间,但我保持结束为零。有什么特定的方法会是最有效的吗?

I need to calculated the runtime of a hash insertion. i have been using clock to do the time but i keep ending up with zero. Is there any certain way that would be the most efficient?

这是我到目前为止的代码:

This is my code for it so far:

cout << "Testing chaining probing...\n";
    HashTable_chaining ChainingHT( ITEM_NOT_FOUND, 101 );
    int i = 0;
    while(i != DataArray.size())
    {
        clock_t tStart = clock();
        ChainingHT.insert(DataArray[i]);
        cout<<"Time taken:"<<(double)(clock() - tStart)/100000<<endl;
        if(i != NULL)
        {
            collision_count++;
        }
        i++;

    }   


推荐答案

散列插入太快,无法测量。 Put

a single hash insert is too quick to be measured. Put

 clock_t tstart = clock();

在程序开始时执行百万次插入

 clock_t tend = clock();

然后以浮点数计算:

 cout << "cpu time=" 
      << ((double)tend - (double)tstart) / CLOCKS_PER_SEC << endl;

典型的当前计算机每秒执行几个数十亿个基本机器指令(但时钟分辨率最好为毫秒)。

Typical current computers do several billions elementary machine instructions per second (but with a clock resolution in milliseconds at best).

这篇关于计算哈希插入的运行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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