c 跨平台計數器

2021-07-10 13:26:24 字數 1764 閱讀 2057

main.cpp清單

#include "timemeasurement.h"

using namespace kagula;

#include using namespace std;

/*title: 跨平台計數器

author: kagula

date: 2016-03-17

purpose: 用來測試程式的時間效能

windows environment:

core i7-4790k

visual studio 2013 update 5

debug mode: 1780.29ms

release mode: 26.8579ms

linux environment:

core i7-4790k

centos 7 in vmware 11.1.2

gcc 4.8.5

1738.01ms

gcc 4.8.5 -o2

0.056ms

linux environment:

阿里雲 haswell 4核

centos 7

gcc 4.8.5

2529.2ms

gcc -o2

0.108ms

在centos下使用下面命令編譯出a.out

g++ main.cpp timemeasurement.cpp

加效能優化引數

g++ main.cpp timemeasurement.cpp -o2

非優化下的測試應該是靠譜的

阿里雲單核效能比core i7-4790k慢50%.

參考《秒 毫秒 微秒 納秒 皮秒。。時間單位換算》

*/int main(int argc, char * argv)

cout << ".";

} cout << endl;

cout << "take time is " << counter.stopcounter() << "ms" << endl;

cin.get();

return 0;

}

timemeasurement.h清單

#ifndef _timemeasurement_h_

#define _timemeasurement_h_

#ifdef win32

#include #else

#include #include #endif

namespace kagula

; void initcounter();

}#endif

timemeasurement.cpp清單

#include "timemeasurement.h"

namespace kagula

#ifdef win32

void elpasedcounter::startcounter()

double elpasedcounter::stopcounter()

#else

void elpasedcounter::startcounter()

double elpasedcounter::stopcounter()

ms = diff.tv_usec / 1000.0f + diff.tv_sec * 1000;

return ms;

}#endif

}

計數器 智慧型計數器簡介

計數器主要是應用於電子科技領域,計數器是一種運用得比較多的時序邏輯電路。計數器可以對數字進行運算,它是一種沒有辦法顯示計算結果的顯示器。隨著電子科技的不斷發展,現在的計數器也實現了智慧型功能。智慧型計數器的出現幫助我們實現了很多高強度生產問題 複雜的技術問題,並且節約了生產成本和人力成本。智慧型計數...

C 指標「計數器」

首先我們區分一下 int nun 0 和int pointer new int 0 表面上看都是乙個整數0,但是實際上num是 獨佔 的,pointer不是,也就是如果我們讓int j num,j就是乙個和num沒關係的數了,而如果我們讓int i pointer 就會不太一樣。i和pointer是...

C 程式設計練習 計數器

description 下面是乙個計數器類的定義,請完成該類的實現,並在 main 函式中演示該類 的應用。class counter 在main 函式裡初始化,讓計數器曾加n 鍵盤輸入 自減一,最後輸出計算器的結果。sample input 18 sample output 6 參考 includ...