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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:36:44+00:00 2026-05-17T16:36:44+00:00

Having read this article I tried to reproduce the example on my Mac. However

  • 0

Having read this article I tried to reproduce the example on my Mac. However my curve for the first example looks completely different and I don’t understand why..

Updating every k-th int

My code is below:

#include <mach/mach_time.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

void mach_absolute_difference(uint64_t end, uint64_t start, struct timespec *tp) {
    uint64_t difference = end - start;
    static mach_timebase_info_data_t info = {0,0};

    if (info.denom == 0)
        mach_timebase_info(&info);

    uint64_t elapsednano = difference * (info.numer / info.denom);

    tp->tv_sec = elapsednano * 1e-9;
    tp->tv_nsec = elapsednano - (tp->tv_sec * 1e9);
}

int main(void)
{
    int len = 64 * 1024 * 1024;
    int *arr = (int *)malloc(sizeof(int)*len);

    uint64_t start,end;
    struct timespec tp;

    start = mach_absolute_time();
    for (int i = 0; i <len; i += K) 
        arr[i] = 0;
    end = mach_absolute_time();

    mach_absolute_difference(end, start, &tp);

    FILE *fp;
    fp=fopen("simple_array.log", "a+");
    fprintf(fp, "%i\t%ld\t%ld\n", K, tp.tv_sec,
            tp.tv_nsec);
    fclose(fp);

    free(arr);
    return 0;
}

I measured the time as described in this blog, hoping that it’s correct. I’m also wondering what I should use to either measure execution time or CPU cycles on a Mac. Or even nicer it would be see the amount of cache hit/misses for a certain function. Shark however only shows l2 cache misses in percentages.

Update this is it when compiled for 32 bit, note that the int size changes from 8 bytes to 4 bytes

Updating every k-th int compiled for 32bit

  • 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-17T16:36:44+00:00Added an answer on May 17, 2026 at 4:36 pm

    A few things:

    • Your work loop has no observable side effects; are you sure the compiler isn’t optimising some or all of it away?
    • An int is probably not one byte in size
    • The bigger you make K, the less overall work you’re doing (i reaches len in fewer iterations)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having just read the first four chapters of Refactoring: Improving the Design of Existing
I have recently read the safe bool idiom article. I had seen this technique
I have read through Scott Hanselman's post on this topic. I found another article
I've tried to read up on a few articles about this, but some of
Having read the threads Is SqlCommand.Dispose enough? and Closing and Disposing a WCF Service
Having read up on quite a few articles on Artificial Life (A subject I
Having read an existing post on stackoverflow and done some reading around on the
Having read Fowler's Refactoring for a while, I still often catch myself thinking I
After having read that QuickSilver was no longer supported by BlackTree and has since
I'm having trouble reading a chunked response when using a StreamReader to read the

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.