💾 Archived View for gmi.noulin.net › gitRepositories › straceMalloc › file › malloc.c.gmi captured on 2023-01-29 at 13:21:37. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

straceMalloc

Log

Files

Refs

README

malloc.c (1915B)

     1 #! /usr/bin/env sheepy
     2 
     3 #include "libsheepyObject.h"
     4 
     5 int argc; char **argv;
     6 
     7 #define COUNT 16
     8 char *pointers[COUNT];
     9 
    10 int main(int ARGC, char** ARGV) {
    11 
    12   argc = ARGC; argv = ARGV;
    13 
    14   puts("malloc");
    15   char *s;
    16   u64 start, end;
    17   range(i, COUNT) {
    18     start = getMonotonicTime();
    19     s = malloc((1<<i)*1024);
    20     pointers[i] = s;
    21     end   = getMonotonicTime();
    22     printf("%d %p size: %dKB, time: %ldns\n", (int)i ,s, 1<<i, end-start);
    23   }
    24 
    25   put
    26 
    27   puts("alloca");
    28   range(i, 12) {
    29     start = getMonotonicTime();
    30     s = alloca((1<<i)*1024);
    31     end   = getMonotonicTime();
    32     printf("alloca %d %p size: %dKB, time: %ldns\n", (int)i ,s, 1<<i, end-start);
    33   }
    34 
    35   put
    36   puts("accesses in malloc");
    37   start = getMonotonicTime();
    38   range(i, COUNT) {
    39     rangeStep(ix, (1<<i)*1024, 4096) {
    40         pointers[i][ix] = '1';
    41     }
    42   }
    43   end   = getMonotonicTime();
    44   printf("1 - access malloc'd buffers - time: %ldms\n", (end-start)/1000000);
    45 
    46   start = getMonotonicTime();
    47   range(i, COUNT) {
    48     rangeStep(ix, (1<<i)*1024, 4096) {
    49         pointers[i][ix] = '1';
    50     }
    51   }
    52   end   = getMonotonicTime();
    53   printf("2 - access malloc'd buffers - time: %ldms\n", (end-start)/1000000);
    54 
    55   put
    56   puts("realloc");
    57   range(i, COUNT) {
    58     
    59     start = getMonotonicTime();
    60     pointers[i] = realloc(pointers[i], (1<<i)*1024 + (1<<i)*1024);
    61     end   = getMonotonicTime();
    62     printf("%d %p size: %dKB, time: %ldns\n", (int)i ,pointers[i], 1<<i, end-start);
    63   }
    64 
    65   put
    66   range(i, COUNT) {
    67     
    68     start = getMonotonicTime();
    69     pointers[i] = realloc(pointers[i], (1<<i)*1024 - 128);
    70     end   = getMonotonicTime();
    71     printf("%d %p size: %dKB, time: %ldns\n", (int)i ,pointers[i], 1<<i, end-start);
    72   }
    73 
    74   put
    75   puts("free");
    76   range(i, COUNT) {
    77     start = getMonotonicTime();
    78     free(pointers[i]);
    79     end   = getMonotonicTime();
    80     printf("%d %p size: %dKB, time: %ldns\n", (int)i ,pointers[i], 1<<i, end-start);
    81   }
    82 }