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 6826471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:09:04+00:00 2026-05-26T22:09:04+00:00

I have run into an interesting performance conundrum but before I start delving into

  • 0

I have run into an interesting performance conundrum but before I start delving into glibc and entering bugs left right and center I just wanted to get to get any insight that might be out there.

I have code that in one of the functions does this:

gettimeofday( &tv, 0);
localtime_r( &tv.tv_sec, &local_tm );
char result[25];
strftime( result, 24, "%Y-%m-%d %H:%M:%S", &local_tm);

The rest of the code is irrelevant for this question. When I replace it with this:

gettimeofday( &tv, 0);
localtime_r( &tv.tv_sec, &local_tm );
char result[25];
snprintf(result, sizeof(result), "%04d-%02d-%02d %02d:%02d:%02d",
         local_tm.tm_year+1900, local_tm.tm_mon+1,
         local_tm.tm_mday, local_tm.tm_hour, local_tm.tm_min,
         local_tm.tm_sec);

on average I get 20% performance boost.

Has anyone ran into this? Is this OS specific?

  • 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-26T22:09:05+00:00Added an answer on May 26, 2026 at 10:09 pm

    POSIX requires strftime to call tzset() (or act as if it did), which on a linux system will likely stat /etc/timezone and other files, which is slow (compared to snprintf). Setting the TZ environment variable will generally give it a great boost.

    As was said in the comments it also localizes the message.

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

Sidebar

Related Questions

I have run into this problem before but never quite solved it. I have
I have run into an interesting problem. I am currently developing php page and
I have run into a very interesting problem trying to debug my custom PHP
We've run into an interesting situation that needs solving, and my searches have turned
I have run into an interesting bug where it appears that when you select
I have run into an interesting problem. I have inherited a database for daemon
Whilst developing a php class i have run into a rather interesting thing within
I have run into an interesting dilema. In a DataMapper class, I am generating
I have run into an interesting problem which I'm pretty sure is the fault
I have run into an interesting problem lately: Lets say I have an array

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.