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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:47:16+00:00 2026-05-26T07:47:16+00:00

I’m writing a small benchmarking library in C which is used to benchmark single

  • 0

I’m writing a small benchmarking library in C which is used to benchmark single functions. The way it works is that you supply the benchmarking function with a pointer to a void function without parameters and the number iterations. The function then returns a struct with information about

However when looking at the individual results I see that the first call takes up a lot of time and then the calls after takes up very little time.

So I’m wondering:

  1. Is this due to instruction caching?
  2. If yes to first question, how does benchmarking tools generally conform to this? Is the first call excluded?
  3. If yes to first question, is there a case when caching is not applied to a function?
  4. If yes to first question, does caching occur on whole functions or segments of a function?
  5. If yes to first question, is there anything else I should consider that I should read up on and understand better?

Data and code

The function which retrieves the time:

double currentTime()
{
    struct timeval time;
    struct timezone timezone;
    gettimeofday(&time, &timezone);
    return time.tv_sec + time.tv_usec * 1e-6;
}

Test result:

0.000319
0.000000
0.000000
0.000000
0.000001
0.000000
0.000000
0.000000
0.000000
0.000000
Total time: 0.000320
Average time: 0.000032
Worst time: 0.000319
Best time: 0.000000

Result without optimizing flag:

13.425430
13.349757
13.482863
13.129472
13.020705
13.672982
13.027595
13.139602
13.028962
13.107892
Total time: 132.385260
Average time: 13.238526
Worst time: 13.672982
Best time: 13.020705

The function being tested which produces this result:

void test()
{
    unsigned int i = 0;
    while(i++ < UINT_MAX){}
}

Make file:

CC = gcc
MAIN = main.c
SOURCES = lib/tb_time_handling.c lib/tb_rendering.c tb_benching.c
OUTPUT = main
FLAGS = -Wall -pedantic -O2

all: main

main: 
    $(CC) $(MAIN) $(SOURCES) -o $(OUTPUT) $(FLAGS)

Github repo with all code:

https://github.com/Ancide/TinyBench

Edit: Forgot to mention compiler and compiler flags

Edit 2: Added git repo with all code in case someone wants to see everything

Edit 3: Added results withouth O2 flag

  • 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-26T07:47:17+00:00Added an answer on May 26, 2026 at 7:47 am

    This is normal in virtual memory operating systems. The first call to a function tends to generate a page fault which loads the code from the executable file into RAM. If you are interested in actual code perf then you ignore the first call. If you are interested in realistic perf measurements then you don’t ignore it.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.