Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6996861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:12:40+00:00 2026-05-27T20:12:40+00:00

inside our app we have to sample something in a high resolution. i have

  • 0

inside our app we have to sample something in a high resolution.

i have seen that the regular NSTimer in objective c , cant go under 50ms.

we need to sample in a rate of about 1ms at least .

this is so strange that there is no 1 way to sample in 1ms when the iphone processor is more that 1ghz !

i had 2 ideas: 1. do a while(1) that maybe will give me the clock, or, use accelerometer sample(is he that fast? ) , i am sure both are not ok .

any idea to this simple problem ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:12:40+00:00Added an answer on May 27, 2026 at 8:12 pm

    It’s really not simple task to implement precise timer of that resolution. To get highly precise timer you probably need to implement your own run loop. If it requires only single timer with now dynamic timer insertion/deletion then it’s implementation rather simple.

    As you said, run the while(…) loop and inside there you need to sleep for some time. This is the most tricky part, cause sometimes the previously actual elapsed time could be bigger/smaller then the actual one so you have to compensate it.

        while( running ) {
    
            gettimeofday(&t_start, NULL);
            {
                double sleep_time = cur_timer->_M->nextFireTime() - elapsedTime;
                if( sleep_time > 0 ) {
                    Thread::sleep(sleep_time); //sleep time is in seconds
                }
            }
            gettimeofday(&t_end, NULL);
    
            elapsedTime += Utils::timeval_diff(t_end, t_start);
    
            if( running ) {
                gettimeofday(&t_start, NULL);
                {
                    //perform all timer callbacks here
                }
                gettimeofday(&t_end, NULL);
            }
    
            elapsedTime += Utils::timeval_diff(t_end, t_start);
        }
    

    This is very simplified version of my own runloop implementation. The main idea here is that you have to keep track of the actual elapsed time and compensate any time overflows.

    Here is the sample output for the 1ms time step:

    period: 0.001000 (0.001000)   elapsed: 0.001160 (0.001160)
    period: 0.001000 (0.002000)   elapsed: 0.000988 (0.002148)
    period: 0.001000 (0.003000)   elapsed: 0.000982 (0.003130)
    period: 0.001000 (0.004000)   elapsed: 0.001003 (0.004133)
    period: 0.001000 (0.005000)   elapsed: 0.001004 (0.005137)
    
    .....
    
    period: 0.001000 (4.280872)   elapsed: 0.001022 (4.299592)
    period: 0.001000 (4.281872)   elapsed: 0.002627 (4.302219)
    period: 0.001000 (4.282872)   elapsed: 0.000018 (4.302237)
    period: 0.001000 (4.283872)   elapsed: 0.000266 (4.302503)
    period: 0.001000 (4.284872)   elapsed: 0.001091 (4.303594)
    period: 0.001000 (4.285872)   elapsed: 0.001026 (4.304620)
    

    To get even more precise results run the timer on a separate thread with high priority.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that I would like to embed inside our companies CMS.
I have a winforms c# app that has an embedded webbrowser control inside it
We have a test case that crashes our big MFC-based app with a heap
I have build server inside our domain (and it needs to be because it
Seems like a simple problem: I have an SVN repo inside our firewall. I
in our application we have a Java applet running inside a .NET browser control.
We have an existing web app built with jQuery Mobile. Our goal is to
We're planning to build some sort of single sign-on feature inside our app. It's
We have a custom section in my app.config file related to our IoC container
I am planing to display Rss feed inside an Androind app I have this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.