added tests
This commit is contained in:
parent
73e2146ed5
commit
a04988cfa2
|
@ -0,0 +1,49 @@
|
|||
//~ 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 не у дел :(
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 3) {
|
||||
fputs("Usage: realloc_speed_test_cpp iterations nobj\n", stderr);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
size_t iterations = (size_t)atoi(argv[1]);
|
||||
size_t nobj = (size_t)atoi(argv[2]);
|
||||
|
||||
std::vector<std::string> v(nobj);
|
||||
|
||||
//std::string app; for(size_t k=0; k<1000; k++) app += ' ';
|
||||
|
||||
size_t i, j, idx;
|
||||
for (i = 0; i < iterations; i++) {
|
||||
idx = (size_t)(rand() % (int)nobj);
|
||||
try {
|
||||
//v[idx] += v[idx];//app;
|
||||
v[idx].resize(i);
|
||||
//for (j = 0; j < i; j++)
|
||||
// v[idx] += ' ';
|
||||
} catch(...) {
|
||||
fprintf(stderr, "Alloc error at i = %lu\n", i);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Success, iterations = %lu, nobj = %lu\n", iterations, nobj);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
//~ time ./realloc_speed_test_c 50000 100000
|
||||
//~ Success, iterations = 50000, nobj = 100000
|
||||
//~
|
||||
//~ real 0m0.313s
|
||||
//~ user 0m0.130s
|
||||
//~ sys 0m0.160s
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zalloc.h"
|
||||
#include "zalloc_ext.h"
|
||||
|
||||
size_t optimal_zalloc_size(size_t size);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 3) {
|
||||
fputs("Usage: realloc_speed_test_cpp iterations nobj\n", stderr);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
size_t iterations = (size_t)atoi(argv[1]);
|
||||
size_t nobj = (size_t)atoi(argv[2]);
|
||||
|
||||
void **p = malloc(sizeof(void *) * nobj);
|
||||
memset(p, 0, sizeof(void *) * nobj);
|
||||
|
||||
//void *app = zmalloc(1000);
|
||||
|
||||
size_t i, j, idx;
|
||||
for (i = 0; i < iterations; i++) {
|
||||
idx = (size_t)(rand() % (int)nobj);
|
||||
//p[idx] = zalloc_append(p[idx], p[idx]);
|
||||
zrealloc_inplace(&p[idx], i);
|
||||
//for (j = 0; j < i; j++)
|
||||
// p[idx] = zalloc_append8(p[idx], ' ');
|
||||
}
|
||||
|
||||
for (i = 0; i < nobj; i++)
|
||||
zfree(p[i]);
|
||||
|
||||
free(p);
|
||||
|
||||
printf("Success, iterations = %lu, nobj = %lu\n", iterations, nobj);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue