public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Eliot Moss <moss@cs.umass.edu>
To: cygwin@cygwin.com
Subject: Re: calloc speed difference
Date: Fri, 12 Jan 2018 22:00:00 -0000	[thread overview]
Message-ID: <caeb25e5-a89d-d6b3-f0e0-2efcf28fb84b@cs.umass.edu> (raw)
In-Reply-To: <46515148-9f8e-6eae-69f9-9bf20921097a@t-online.de>

On 1/12/2018 9:06 AM, Christian Franke wrote:

> This variant of the above code adds one write access to each 4KiB page (guarded by "volatile" to 
> prevent dead assignment optimization):
> 
> #include <stdio.h>
> #include <stdlib.h>
> #define ALLOCATION_SIZE (100 * 1024 * 1024)
> int main (int argc, char *argv[]) {
>      for (int i = 0; i < 1000; i++) {
>          void *temp = calloc(ALLOCATION_SIZE, 1);
>          if ( temp == NULL ) {
>             printf("drat! calloc returned NULL\n");
>             return 1;
>          }
>          for (int j = 0; j < ALLOCATION_SIZE; j += 4096)
>            ((volatile char *)temp)[j] = (char)i;
>          free(temp);
>      }
>      return 0;
> }
> 
> Results:
> 
> Cygwin: ~310s
> MinGW: ~210s

Good analysis!  There remains a lot of room for improvement, but this
shows good reasons to dig deeper to understand what goes on with large
allocations.

EM

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  parent reply	other threads:[~2018-01-12 22:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12  7:19 Lee
2018-01-12  8:38 ` Eliot Moss
2018-01-12  9:07 ` Marco Atzeri
2018-01-12 10:52   ` Lee
2018-01-21 11:01     ` Marco Atzeri
2018-01-12 14:05 ` Christian Franke
2018-01-12 14:33   ` Corinna Vinschen
2018-01-12 19:59     ` cyg Simple
2018-01-12 20:07       ` cyg Simple
2018-01-12 20:41       ` Corinna Vinschen
2018-01-12 22:34         ` cyg Simple
2018-01-13 10:48           ` Lee
2018-01-13 10:04     ` Lee
2018-01-12 22:00   ` Eliot Moss [this message]
2018-01-13  8:35   ` Lee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=caeb25e5-a89d-d6b3-f0e0-2efcf28fb84b@cs.umass.edu \
    --to=moss@cs.umass.edu \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).