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