2011-06-14 13:02:33 +04:00
|
|
|
|
//~ kolan@nickolay-842 ~/dev/c/realloc_speed_test(default) $ time ./realloc_speed_test_cpp 50000 100000
|
|
|
|
|
//~ Success, iterations = 50000, nobj = 100000
|
|
|
|
|
//~
|
|
|
|
|
//~ real 0m0.818s
|
|
|
|
|
//~ user 0m0.290s
|
|
|
|
|
//~ sys 0m0.520s
|
|
|
|
|
|
|
|
|
|
//~ при увеличении с 50000 до 60000 std::string лезут в своп, дождаться завершения не получится,
|
|
|
|
|
//~ в то время как realloc(), xrealloc() и zrealloc() спокойно работают при кратном увеличении nobj.
|
|
|
|
|
//~ во всех тестах zrealloc показала наилучшие результаты :), приблизительно в 1.5 раза быстрее xrealloc() и realloc().
|
|
|
|
|
//~ std::string не у дел :(
|
|
|
|
|
|
2011-06-09 19:00:04 +04:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2011-06-14 13:02:33 +04:00
|
|
|
|
if (argc != 3) {
|
|
|
|
|
fputs("Usage: realloc_speed_test_cpp iterations nobj\n", stderr);
|
2011-06-09 19:00:04 +04:00
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t iterations = (size_t)atoi(argv[1]);
|
|
|
|
|
size_t nobj = (size_t)atoi(argv[2]);
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> v(nobj);
|
|
|
|
|
|
|
|
|
|
size_t i, idx, sz;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < iterations; i++) {
|
|
|
|
|
idx = rand() % nobj;
|
2011-06-14 13:02:33 +04:00
|
|
|
|
sz = i;
|
2011-06-09 19:00:04 +04:00
|
|
|
|
try {
|
|
|
|
|
v[idx].resize(sz);
|
2011-07-17 21:41:45 +04:00
|
|
|
|
|
2011-06-09 19:00:04 +04:00
|
|
|
|
} catch(...) {
|
|
|
|
|
fprintf(stderr, "Alloc error at i = %lu\n", i);
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-14 13:02:33 +04:00
|
|
|
|
printf("Success, iterations = %lu, nobj = %lu\n", iterations, nobj);
|
2011-06-09 19:00:04 +04:00
|
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|