|
- c++:
- double millisecondNow() {
- struct timeval tv;
- gettimeofday(&tv, nullptr);
- log("CurrentTime MillSecond %f", (double)tv.tv_sec * 1000 + (double)tv.tv_usec / 1000);
- return (double)tv.tv_sec * 1000 + (double)tv.tv_usec / 1000;
- }
- auto milliS1=millisecondNow();
- CCLOG ("milliS1: %f \n",milliS1);
- for( int i = 0; i < 100000000; i ++ )
- {
- }
- auto milliS2=millisecondNow();
- CCLOG ("milliS2: %f \n",milliS2);
- CCLOG ("消耗秒: %f \n",(milliS2-milliS1)/1000);
- js:
- var time1 = Date.now();
- cc.log("time1:" + time1);
- for (var i = 0, lenI = 100000000; i < lenI; i++) {
- }
- var time2 = Date.now();
- cc.log("time2:" + Date.now());
- cc.log("use time:" + ((time2 - time1)/1000)+"s");
- lua:
- local socket = require "socket"
- local t0 = socket.gettime()
- -- do something
- for i=1,100000000 do
-
- end
- local t1 = socket.gettime()
- print("used time: "..t1)
- print("used time: "..t0)
- print("used time: "..t1-t0.."s")
复制代码
|
|