Is there an objective-c/iPhone version of currentTimeMillis() from Java?

前端 未结 5 1857
广开言路
广开言路 2021-02-19 03:57

I need to time some events in the app I\'m working on. In Java i used to be able to call currentTimeMillis() but there doesnt seem to be a version in Objective-c. Is there a way

5条回答
  •  感动是毒
    2021-02-19 04:47

    To get very cheap very precise time, you can use gettimeofday(), which is a C Function of the BSD kernel. Please read the man page for full details, but here's an simple example:

    struct timeval t;
    gettimeofday(&t, NULL);
    
    long msec = t.tv_sec * 1000 + t.tv_usec / 1000;
    

提交回复
热议问题