commit debdd416af148e4fec8bc4f8aa37fe936917cd93
parent 77cb3738174ea8789494ccf65250db994e50be8c
Author: Remy Noulin <loader2x@gmail.com>
Date: Tue, 30 Jan 2018 14:30:29 +0100
add accesses to malloc'd buffers
malloc.c | 37 ++++++++++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 7 deletions(-)
Diffstat:
| M | malloc.c | | | 37 | ++++++++++++++++++++++++++++++------- |
1 file changed, 30 insertions(+), 7 deletions(-)
diff --git a/malloc.c b/malloc.c
@@ -4,28 +4,51 @@
int argc; char **argv;
+#define COUNT 16
+char *pointers[COUNT];
+
int main(int ARGC, char** ARGV) {
argc = ARGC; argv = ARGV;
- puts("alloc");
+ puts("malloc");
char *s;
u64 start, end;
- range(i, 16) {
+ range(i, COUNT) {
start = getMonotonicTime();
s = malloc((1<<i)*1024);
+ pointers[i] = s;
end = getMonotonicTime();
- printf("%d %p size: %ldKB, time: %ldns\n", (int)i ,s, 1<<i, end-start);
+ printf("%d %p size: %dKB, time: %ldns\n", (int)i ,s, 1<<i, end-start);
}
- s[0] = 's';
- s[1] = 0;
- puts(s);
+ put
+ puts("alloca");
range(i, 12) {
start = getMonotonicTime();
s = alloca((1<<i)*1024);
end = getMonotonicTime();
- printf("alloca %d %p size: %ldKB, time: %ldns\n", (int)i ,s, 1<<i, end-start);
+ printf("alloca %d %p size: %dKB, time: %ldns\n", (int)i ,s, 1<<i, end-start);
+ }
+
+ put
+ puts("accesses in malloc");
+ start = getMonotonicTime();
+ range(i, COUNT) {
+ rangeStep(ix, (1<<i)*1024, 4096) {
+ pointers[i][ix] = '1';
+ }
+ }
+ end = getMonotonicTime();
+ printf("1 - access malloc'd buffers - time: %ldms\n", (end-start)/1000000);
+
+ start = getMonotonicTime();
+ range(i, COUNT) {
+ rangeStep(ix, (1<<i)*1024, 4096) {
+ pointers[i][ix] = '1';
+ }
}
+ end = getMonotonicTime();
+ printf("2 - access malloc'd buffers - time: %ldms\n", (end-start)/1000000);
}