diff --git a/c/malloc_speed_test/malloc_speed_test.c b/c/malloc_speed_test/malloc_speed_test.c new file mode 100644 index 0000000..f812ab1 --- /dev/null +++ b/c/malloc_speed_test/malloc_speed_test.c @@ -0,0 +1,14 @@ +#include + +const unsigned long long MAX_I=0x00ffffff; + +int main() +{ + unsigned long long i; + + for (i = 0; i < MAX_I; i++) + free(malloc(1)); + + return 0; +} + diff --git a/c/malloc_speed_test/run.sh b/c/malloc_speed_test/run.sh new file mode 100755 index 0000000..1f7b393 --- /dev/null +++ b/c/malloc_speed_test/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "malloc_speed_test.c test:" +cc -O2 malloc_speed_test.c -o malloc_speed_test && time ./malloc_speed_test + +echo -e "\n\nvector_add.cpp test:" +c++ -O2 vector_add.cpp -o vector_add && time ./vector_add diff --git a/c/malloc_speed_test/vector_add.cpp b/c/malloc_speed_test/vector_add.cpp new file mode 100644 index 0000000..e87affe --- /dev/null +++ b/c/malloc_speed_test/vector_add.cpp @@ -0,0 +1,17 @@ +#include + +using namespace std; + +const unsigned long long MAX_I = 0x00ffffff; + +int main() +{ + unsigned long long i; + + vector v; + + for (i = 0; i < MAX_I; i++) + v.push_back(0); + + return 0; +}