G
goose
Hello all
Thanks for the time and effort you've poured into
my malloc wrappers. I've updated it to cater for
one of the criticisms
("it's stunningly slow" - thanks Paul .
The remaining two issues which I intend to take
care of (errors on realloc/free and maybe a
sentinel) I'll look at later this week.
I've changed the find_ptr function to search
from the front and back at the same time with
lovely results (see below). I've also added
a profile.c file which contains the main function
for the profile application that generated these
results.
I've also placed some comments in the profile.c
file to explain what the numbers mean (they're
basically the result of calling clock() before and
after running the tests in profile.c and printing
the difference).
Feel free to download the new and the old
versions to compare.
You can find this at
http://www.lelanthran.com/downloads
You'll get an option to download both the old
os_mem ("Custom C memory routines") and the new
os_mem ("(take 2)Custom C memory routines").
Those two options should appear on the menu on
the right.
The results are as follows:
[number in first column is how many times the
function in 2nd column was run and the last
number is the time it took]
1.
This is the results of replacing the
os_mem_[malloc|realloc|free] calls
with plain [malloc|realloc|free].
(i.e. os_mem does not get used).
-----------------------------------
1280 mallocs = 0
5120 mallocs = 0
10240 mallocs = 1
20480 mallocs = 0
40960 mallocs = 2
81920 mallocs = 3
-----------------------------------
1280 reallocs = 0
5120 reallocs = 0
10240 reallocs = 1
20480 reallocs = 0
40960 reallocs = 2
81920 reallocs = 4
-----------------------------------
1280 frees = 0
5120 frees = 2
10240 frees = 0
20480 frees = 1
40960 frees = 3
81920 frees = 4
-----------------------------------
2.
This is the results from the old implementation
of find_ptr (search from the beginning for the
pointer in question). The add_to_list also
searched from the beginning every single time.
-----------------------------------
1280 mallocs = 0
5120 mallocs = 16
10240 mallocs = 57
20480 mallocs = 541
40960 mallocs = 5273
81920 mallocs = 24277
-----------------------------------
1280 reallocs = 2
5120 reallocs = 30
10240 reallocs = 120
20480 reallocs = 1071
40960 reallocs = 10547
81920 reallocs = 48488
-----------------------------------
1280 frees = 1
5120 frees = 0
10240 frees = 1
20480 frees = 2
40960 frees = 3
81920 frees = 8
-----------------------------------
3.
This is the results using the new version
of find_ptr (search from beginning and
end at the same time). Also note that
in this version add_to_list uses find_ptr
to search for an insertion point, the
previous algorithm searched from the
beginning every time.
-----------------------------------
1280 mallocs = 0
5120 mallocs = 1
10240 mallocs = 4
20480 mallocs = 12
40960 mallocs = 48
81920 mallocs = 187
-----------------------------------
1280 reallocs = 0
5120 reallocs = 3
10240 reallocs = 6
20480 reallocs = 16
40960 reallocs = 57
81920 reallocs = 205
-----------------------------------
1280 frees = 0
5120 frees = 1
10240 frees = 1
20480 frees = 1
40960 frees = 4
81920 frees = 7
-----------------------------------
Seeing as how I was not aiming for raw performance,
the new version performs "good enough" (besides,
anyone doing 81920 mallocs in a program shouldn't
notice a slowdown thats around a second on an
underpowered machine like I tested on).
Feel free to download and experiment (liberal licensing
included this time, not GPL).
goose,
Thanks for the time and effort you've poured into
my malloc wrappers. I've updated it to cater for
one of the criticisms
("it's stunningly slow" - thanks Paul .
The remaining two issues which I intend to take
care of (errors on realloc/free and maybe a
sentinel) I'll look at later this week.
I've changed the find_ptr function to search
from the front and back at the same time with
lovely results (see below). I've also added
a profile.c file which contains the main function
for the profile application that generated these
results.
I've also placed some comments in the profile.c
file to explain what the numbers mean (they're
basically the result of calling clock() before and
after running the tests in profile.c and printing
the difference).
Feel free to download the new and the old
versions to compare.
You can find this at
http://www.lelanthran.com/downloads
You'll get an option to download both the old
os_mem ("Custom C memory routines") and the new
os_mem ("(take 2)Custom C memory routines").
Those two options should appear on the menu on
the right.
The results are as follows:
[number in first column is how many times the
function in 2nd column was run and the last
number is the time it took]
1.
This is the results of replacing the
os_mem_[malloc|realloc|free] calls
with plain [malloc|realloc|free].
(i.e. os_mem does not get used).
-----------------------------------
1280 mallocs = 0
5120 mallocs = 0
10240 mallocs = 1
20480 mallocs = 0
40960 mallocs = 2
81920 mallocs = 3
-----------------------------------
1280 reallocs = 0
5120 reallocs = 0
10240 reallocs = 1
20480 reallocs = 0
40960 reallocs = 2
81920 reallocs = 4
-----------------------------------
1280 frees = 0
5120 frees = 2
10240 frees = 0
20480 frees = 1
40960 frees = 3
81920 frees = 4
-----------------------------------
2.
This is the results from the old implementation
of find_ptr (search from the beginning for the
pointer in question). The add_to_list also
searched from the beginning every single time.
-----------------------------------
1280 mallocs = 0
5120 mallocs = 16
10240 mallocs = 57
20480 mallocs = 541
40960 mallocs = 5273
81920 mallocs = 24277
-----------------------------------
1280 reallocs = 2
5120 reallocs = 30
10240 reallocs = 120
20480 reallocs = 1071
40960 reallocs = 10547
81920 reallocs = 48488
-----------------------------------
1280 frees = 1
5120 frees = 0
10240 frees = 1
20480 frees = 2
40960 frees = 3
81920 frees = 8
-----------------------------------
3.
This is the results using the new version
of find_ptr (search from beginning and
end at the same time). Also note that
in this version add_to_list uses find_ptr
to search for an insertion point, the
previous algorithm searched from the
beginning every time.
-----------------------------------
1280 mallocs = 0
5120 mallocs = 1
10240 mallocs = 4
20480 mallocs = 12
40960 mallocs = 48
81920 mallocs = 187
-----------------------------------
1280 reallocs = 0
5120 reallocs = 3
10240 reallocs = 6
20480 reallocs = 16
40960 reallocs = 57
81920 reallocs = 205
-----------------------------------
1280 frees = 0
5120 frees = 1
10240 frees = 1
20480 frees = 1
40960 frees = 4
81920 frees = 7
-----------------------------------
Seeing as how I was not aiming for raw performance,
the new version performs "good enough" (besides,
anyone doing 81920 mallocs in a program shouldn't
notice a slowdown thats around a second on an
underpowered machine like I tested on).
Feel free to download and experiment (liberal licensing
included this time, not GPL).
goose,