gettimeofday

iPhone: How to get current milliseconds?

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: What is the best way to get the current system time milliseconds? 回答1: [[ NSDate date ] timeIntervalSince1970 ]; It returns the number of seconds since epoch as a double. I'm almost sure you can access the milliseconds from the fractional part. 回答2: If you're looking at using this for relative timing (for example for games or animation) I'd rather use CACurrentMediaTime() double CurrentTime = CACurrentMediaTime (); Which is the recommended way; NSDate draws from the networked synch-clock and will occasionally hiccup when re

What are vdso and vsyscall?

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I did sudo cat /proc/1/maps -vv I am attempting to make sense of the output.I can see a lot of shared libraries being mapped to the memory mapping segment as expected. 7f3c00 13700 0-7f3c00179000 r-xp 00000000 08:01 21233923 /lib/x86_64-linux-gnu/libdbus-1.so.3.5.8 7f3c00179000-7f3c00379000 ---p 00042000 08:01 21233923 /lib/x86_64-linux-gnu/libdbus-1.so.3.5.8 7f3c00379000-7f3c0037a000 r--p 00042000 08:01 21233923 /lib/x86_64-linux-gnu/libdbus-1.so.3.5.8 7f3c0037a000-7f3c0037b000 rw-p 00043000 08:01 21233923 /lib/x86_64-linux-gnu/libdbus-1.so

What should I use to replace gettimeofday() on Windows?

匿名 (未验证) 提交于 2019-12-03 01:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm writing a portable Socket class that supports timeouts for both sending and receiving... To implement these timeouts I'm using select() .... But, I sometimes need to know how long I was blocked inside select() which of course on Linux I would implement by calling gettimeofday() before and after I call select() and then using timersub() to calculate the delta... Given that select() on Windows accepts struct timeval for it's timeout, what method should I used to replace gettimeofday() on Windows? 回答1: I ended up finding this page:

Swift: gettimeofday and Unsafe Pointers

流过昼夜 提交于 2019-12-02 05:51:43
问题 The code in Swift ... var time:timeval? gettimeofday(UnsafePointer<timeval>, UnsafePointer<()>) // this is the method expansion before filling in any data ... The code in Objective C ... struct timeval time; gettimeofday(&time, NULL); ... I have been trying to find more information on UnsafePointer and alternatives to passing NULL, but I may be barking up the wrong tree. If anyone knows how to get the equivilant code working in Swift, that would be great. If there is a good explanation of

usleep() to calculate elapsed time behaves weird

拜拜、爱过 提交于 2019-12-02 04:20:35
问题 I am calculating time elapsed in milli seconds for each successive call to handler function using the code below. When i use usleep(1000) i.e. 1 ms time difference between each call is 10 ms and when i use usleep(1000000) i.e. 1 sec surprisingly time interval between each call falls down to less than 1 ms. Following is the code snippet : #include<stdio.h> #include<stdlib.h> #include<sys/time.h> #include<unistd.h> struct timeval start_time; void handler(int); int main() { struct timeval

Seconds calculation using rdtsc

拈花ヽ惹草 提交于 2019-12-02 03:27:41
问题 Here is the code to calculate CPU time but it's not correct because when I use gettimeofday it gives me correct time in ms. I am running my process on one processor and its clock runs at 800MHz. My knowledge about rdtsc is as follows: Rdtsc returns number of cycles Using those # of cycles one can calculate the CPU time given the clock rate (800 MHZ) unsigned long long a,b; unsigned long cpuMask; cpuMask = 2; // bind to cpu 1 if(!sched_setaffinity(0, sizeof(cpuMask), &cpuMask)) fprintf(stderr,

gettimeofday及其相关时间函数

ぐ巨炮叔叔 提交于 2019-11-30 21:37:23
1 、 gettimeofday 函数 该函数的头文件在 /usr/include/sys/time.h 头文件中。 函数原型:int gettimeofday(struct timeval *tv, struct timezone *tz); 用到两个结构体: timeval 和 timezone 这两个结构体定义在 /usr/include/linux/time.h 头文件中。 一秒=1000000 微秒 函数作用:会把得到从 1970 年 1 月 1 日 0 时 0 分 0 秒到现在的秒数返回到第一个参数指向的结构体中,第二个参数是关于时区,如果不考虑填入 NULL 。 函数成功返回 0 ,否则返回 -1 , 错误代码存于 errno。 可以利用该函数来计算一个程序的运行时间,只需在程序前后调用该函数,并且后来的函数时间减去开始的函数时间就可以。注意单位的转变。 2、time()函数 time函数声明:time_t time(time_t *t) 头文件: <time.h> 由声明可知,这里有一个特殊类型 time_t类型 ;相当于 long int 类型。函数参数为time_t类型变量的地址。 eg: time 函数接收 time_t 类型的变量地址为参数,计算返回 1970 年 1 月 1 日 00:00:00 到现在的秒数,并存储在变量中。 特殊: time (

时间获取函数

血红的双手。 提交于 2019-11-30 02:18:07
目录 time函数 clock_gettime函数 gettimeofday函数 由Linux内核提供的基本时间是自1970-01-01 00:00:00 +0000 (UTC)这一特定时间以来经过的秒数,这种描述是以数据类型time_t表示的,我们称其为日历时间。 获得日历时间的函数有3个:time、clock_gettime和gettimeofday。 time函数 #include <time.h> //成功返回日历时间,出错返回-1;若time非NULL,则也通过其返回时间值 time_t time(time_t *time); #include <stdio.h> #include <string.h> #include <time.h> void print_time() { time_t seconds = time(NULL); printf("seconds = %ld\n", seconds); } int main() { print_time(); return 0; } clock_gettime函数 clock_gettime函数可用于获取指定时钟的时间,返回的时间通过struct timespec结构保存,该结构把时间表示为秒和纳秒。 #include <time.h> struct timespec { time_t tv_sec; /*

What should I use to replace gettimeofday() on Windows?

ぐ巨炮叔叔 提交于 2019-11-28 17:57:05
I'm writing a portable Socket class that supports timeouts for both sending and receiving... To implement these timeouts I'm using select() .... But, I sometimes need to know how long I was blocked inside select() which of course on Linux I would implement by calling gettimeofday() before and after I call select() and then using timersub() to calculate the delta... Given that select() on Windows accepts struct timeval for it's timeout, what method should I used to replace gettimeofday() on Windows? dicroce I ended up finding this page: gettimeofday() on windows [edit: link removed because it

how to use gettimeofday() or something equivalent with Visual Studio C++ 2008?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 14:47:01
Could someone please help me to use gettimeofday() function with Visual Studio C++ 2008 on Windows XP? here is a code that I found somewhere on the net: #include < time.h > #include <windows.h> #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 #else #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL #endif struct timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; int gettimeofday(struct timeval *tv, struct timezone *tz) { FILETIME ft; unsigned __int64 tmpres = 0; static int tzflag