Page 3 of 3 FirstFirst 123
Results 21 to 23 of 23

Thread: How can this program run faster on my Atom than on my i7?

  1. #21
    Join Date
    Jun 2007
    Location
    Minneapolis, MN
    Beans
    749
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can this program run faster on my Atom than on my i7?

    I found the solution to my problem.
    This better_sleep.c function that I found makes it run at the speed I Want:

    Code:
    /***********************************
     better_sleep.c
    ***********************************/
    #include <errno.h>
    #include <time.h>
    int better_sleep (double sleep_time)
    {
      struct timespec tv;
      /* Construct the timespec from the number of whole seconds... */
      tv.tv_sec = (time_t) sleep_time;
      /* ... and the remainder in nanoseconds. */
      tv.tv_nsec = (long) ((sleep_time - tv.tv_sec) * 1e+9);
      while (1)  
      {
        /* Sleep for the time specified in tv. If interrupted by a
        signal, place the remaining time left to sleep back into tv. */
        int rval = nanosleep (&tv, &tv);
        if (rval == 0)
        /* Completed the entire sleep time; all done. */
        return 0;
        else if (errno == EINTR)
        /* Interrupted by a signal. Try again. */
        continue;
        else
        /* Some other error; bail out. */
        return rval;
      }
    return 0;
    }
    Thread marked solved, thanks to all.
    Moderation in all things; including moderation.

  2. #22
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How can this program run faster on my Atom than on my i7?

    Can we politely make you notice that this is just a wrapper over the nanosleep() function that was recommended to you 2 weeks ago? (see post #14)

  3. #23
    Join Date
    Jun 2007
    Location
    Minneapolis, MN
    Beans
    749
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How can this program run faster on my Atom than on my i7?

    Quote Originally Posted by ofnuts View Post
    Can we politely make you notice that this is just a wrapper over the nanosleep() function that was recommended to you 2 weeks ago? (see post #14)
    Duly noted.

    I am just getting started programming in C again after about 20 years.
    I learned C with the Borland Turbo C compiler for DOS.
    It had a lot of high level functions I was using, so I am just now finding that I didn't know C as well as I thought I did.

    Thank you all for you help, and patience.
    Moderation in all things; including moderation.

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •