1. 程式人生 > >能自己寫函式就別調用庫函式 後者時間耗時更多

能自己寫函式就別調用庫函式 後者時間耗時更多

#include <ctime>
#include <iostream>
#include <cmath>

using namespace std;
const int N = 1024;

int main(void)
{
    int i, M;
    time_t t1 = time(NULL);
    for(int r = 0; r < 100000000; r++)
        for(i=N,M=1;(i=i/2)!=1;M++);
    time_t t2 = time(NULL);
    for(int r = 0; r < 100000000
; r++) M = log(N)/log(2); time_t t3 = time(NULL); cout << "time1:" << t2 - t1 << "\ntime2:" << t3 - t2 << endl; return 0; } /* * res: * time1:4 * time2:13 */