Ecere SDK/eC Forums https://ec-lang.org/community/ Print view |
|
GetTime()获取的时间单位是什么? https://ec-lang.org/community/viewtopic.php?f=30&t=345 |
Page 1 of 1 |
Author: | janksenhu [ Sat Feb 02, 2013 6:51 pm ] |
Post subject: | GetTime()获取的时间单位是什么? |
GetTime()获取的时间单位是什么?秒,毫秒,纳秒? 是从1970年到现在的秒数吗? time = GetTime(); for(c=0;c<10000;c++){ Print("hello world") ; } time2 = GetTime(); Print((double)time-(double)time2) ; |
Author: | janksenhu [ Sat Feb 02, 2013 7:48 pm ] |
Post subject: | Re: GetTime()获取的时间单位是什么? |
来源于网络:使用常规旧 timeGetTime() 做计时不可靠许多基于 Windows 的操作系统上,因为系统计时器的粒度可高达 10-15 毫秒,也就是说, timeGetTime() 只是精确到 10-15 毫秒为单位)。[注高粒度像 Windows NT 中,基于 NT 的运作系统出现于 2000 年和 XP。Windows 95 和 98 往往有很多好的粒度,约 1 5 毫秒。] 而我们查看Time的源码:http://myecere.googlecode.com/svn/trunk ... ys/Time.ec,是调用了windows的api,这样的话,时间太不准确了 public Time GetTime(void) { #if defined(__WIN32__) return timeGetTime() / 1000.0; #elif defined(__unix__) || defined(__APPLE__) struct timeval tp; struct timezone tzp; static int secbase = 0; gettimeofday(&tp, &tzp); if(!secbase) { secbase = tp.tv_sec; return tp.tv_usec / 1000000.0; } return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0; #endif } |
Author: | jerome [ Sat Feb 02, 2013 8:37 pm ] |
Post subject: | Re: GetTime()获取的时间单位是什么? |
Hi janksenhu, GetTime() returns the time in seconds, from no particular moment (In Windows it happens to be the time since Windows was started, wrapping around every 49.71 days). It is meant to be used as delta only, from an earlier moment. For getting the current time, use: Code: Select all
To convert this into seconds since 1970, use: Code: Select all
If you have: Code: Select all
At some point in the past we were using timeBeginPeriod() to change that resolution, but that code is commented out right now. Please let me know if you run into a limitation or if you find a way to improve on this Regards, Jerome |
All times are UTC-05:00 | Page 1 of 1 |
Powered by phpBB® Forum Software © phpBB Limited |