calloc speed difference

Eliot Moss moss@cs.umass.edu
Fri Jan 12 22:00:00 GMT 2018


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



More information about the Cygwin mailing list