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

  • Home
  • SEARCH
  • 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 6564455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:58:07+00:00 2026-05-25T13:58:07+00:00

is it worth keeping a local copy of struct tm and update it only

  • 0

is it worth keeping a local copy of struct tm and update it only when required; below func is not thread safe… also I’ve seen only 6 to 7% of CPU time can be saved…

struct tm* custom_localtime (time_t now_sec)
{

    static time_t cache_sec;
    static struct tm tms;

    if (now_sec != cache_sec) {
        cache_sec = now_sec;
        localtime_r(&cache_sec, &(tms));
    }

    return(&tms);
}

Additional details:
– my app makes more than 3000/sec calls to localtime_r()

found out at least 33% CPU time saving when I cache time-stamp strings of the format "2011-12-09 10:32:45" againt time_t seconds

thank you all nos, asc99c and Mircea.

  • 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-25T13:58:08+00:00Added an answer on May 25, 2026 at 1:58 pm

    I would probably have mentioned the 3000/s call rate in your question! Do it. I recently was profiling generation of a screen which was calling localtime approx 1,000,000 * 10,000 times.

    The nested loops could have been improved substantially with a bit of thought, but what I saw was about 85% of CPU time was used by localtime. Simply caching the result so it was only called 10,000 times cut 85% of the time off page generation, and that made it easily fast enough.

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

Sidebar

Related Questions

Are primitives worth keeping? Should all the deprecated stuff be deleted? Do we need
Is learning Objective-J worth it, considering the limited number of Objective-J tutorials? Also, what
Note: It is worth noting that the mail() function is not suitable for larger
Java Tutorials (Set Implementations) : One thing worth keeping in mind about HashSet is
Is it worth learning the convention or is it a bane to readability and
Is it worth designing a system to expect test accounts and products to be
Is it worth it to develop WAP webpage for cellular since now cellular have
Hopefully a picture is worth a thousand lines of code because I don't want
Is it worth changing my code to be more portable and able to deal
Is it worth to obfuscate java web application? and why?

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.