マイ怠惰...
これは80 * 60 * 5
の期間の結果(Hzでは、x分秒をX)ある:ここ
Process only:: mean: 0.00356445 in seconds
Alloc Dealloc:: mean: 0.0743379 in seconds
コードと冗長出力する。
割り当て - 毎回割り当て解除
class AllocEvery
{
public:
int doSomething()
{
double pi, gold, ogh;
std::string den_rit, jobs, bill;
char c_str[64];
pi = 3.1415926535;
gold = 1.6180339887;
ogh = 0.0000000033;
ogh += pi;
ogh += gold;
jobs = "Being the richest man in the cemetery doesn't matter to me. Going to bed at night saying we've done something wonderful, that's what matters to me.";
bill = "Your most unhappy customers are your greatest source of learning.";
den_rit = "UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.";
}
};
のみの
プロセス:
class ProcessOnly
{
public:
double pi, gold, ogh;
std::string den_rit, jobs, bill;
char c_str[64];
int doSomething()
{
pi = 3.1415926535;
gold = 1.6180339887;
ogh = 0.0000000033;
ogh += pi;
ogh += gold;
jobs = "Being the richest man in the cemetery doesn't matter to me. Going to bed at night saying we've done something wonderful, that's what matters to me.";
bill = "Your most unhappy customers are your greatest source of learning.";
den_rit = "UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.";
}
};
異なる実験から主
int main (int argc, char **argv)
{
int max = 80 * 60 * 5; // Rate * Seconds * Minutes
struct timespec time1, time2;
double time_diff = .0;
AllocEvery obj; /// ProcessOnly obj;
clock_gettime (CLOCK_MONOTONIC, &time1);
for (int i = 0; i < max; i++)
{
obj.doSomething();
}
clock_gettime (CLOCK_MONOTONIC, &time2);
time_diff = time2.tv_sec - time1.tv_sec + (time2.tv_nsec - time1.tv_nsec)/BILLION;
std::cout << "Process only:: Elapsed time: " << time_diff << std::endl;
return 0;
}
出力:この場合
[email protected]:~/C_denemeler/tryspeed_cpp$ ./a.out
------------> Alloc - Dealloc Everytime:: Elapsed time: 0.075384
[email protected]:~/C_denemeler/tryspeed_cpp$ ./a.out
------------> Alloc - Dealloc Everytime:: Elapsed time: 0.0741677
[email protected]:~/C_denemeler/tryspeed_cpp$ ./a.out
------------> Alloc - Dealloc Everytime:: Elapsed time: 0.074426
[email protected]:~/C_denemeler/tryspeed_cpp$ ./a.out
------------> Alloc - Dealloc Everytime:: Elapsed time: 0.0740817
[email protected]:~/C_denemeler/tryspeed_cpp$ ./a.out
------------> Alloc - Dealloc Everytime:: Elapsed time: 0.0734898
[email protected]:~/C_denemeler/tryspeed_cpp$ ./a.out
------------> Alloc - Dealloc Everytime:: Elapsed time: 0.0747045
[email protected]:~/C_denemeler/tryspeed_cpp$ ./a.out
------------> Alloc - Dealloc Everytime:: Elapsed time: 0.0727975
[email protected]:~/C_denemeler/tryspeed_cpp$ ./a.out
------------> Alloc - Dealloc Everytime:: Elapsed time: 0.0772903
[email protected]:~/C_denemeler/tryspeed_cpp$ ./a.out
------------> Alloc - Dealloc Everytime:: Elapsed time: 0.0726992
[email protected]:~/C_denemeler/tryspeed_cpp$ ./p.out
------------> Process only:: Elapsed time: 0.00806864
[email protected]:~/C_denemeler/tryspeed_cpp$ ./p.out
------------> Process only:: Elapsed time: 0.00727956
[email protected]:~/C_denemeler/tryspeed_cpp$ ./p.out
------------> Process only:: Elapsed time: 0.00202144
[email protected]:~/C_denemeler/tryspeed_cpp$ ./p.out
------------> Process only:: Elapsed time: 0.00195636
[email protected]:~/C_denemeler/tryspeed_cpp$ ./p.out
------------> Process only:: Elapsed time: 0.00203696
[email protected]:~/C_denemeler/tryspeed_cpp$ ./p.out
------------> Process only:: Elapsed time: 0.00387936
[email protected]:~/C_denemeler/tryspeed_cpp$ ./p.out
------------> Process only:: Elapsed time: 0.00276425
[email protected]:~/C_denemeler/tryspeed_cpp$ ./p.out
------------> Process only:: Elapsed time: 0.00200299
[email protected]:~/C_denemeler/tryspeed_cpp$ ./p.out
------------> Process only:: Elapsed time: 0.00207049
、 '最初の定義、使用everytime'は良好です。しかし、その差はごく小さいので、気づかないでしょう。 – GMichael
ありがとうございました!私の通信速度はこれらのレベルには達しませんが、速度が480,000,000ボー(USB 2.0)に達する場合でも問題はありませんか? –
実際の違いは、 'genAndSend_setInt32Command'内のローカル変数の初期化です。それは数ダニ以上でなければならない。また、好きなときに測定することもできます。 – GMichael