вынесены функции для теста

This commit is contained in:
Kolan Sh 2011-06-15 20:00:24 +04:00
parent c833f2b6c6
commit ffb9a25ddd
6 changed files with 63 additions and 57 deletions

View File

@ -17,8 +17,8 @@ long_line_column=72
[files]
current_page=1
FILE_NAME_0=121;C;0;16;1;1;1;/home/kolan/dev/c/realloc_speed_test/realloc_speed_test_c.c;0
FILE_NAME_1=144;C++;0;16;1;1;1;/home/kolan/dev/c/realloc_speed_test/realloc_speed_test_cpp.cpp;0
FILE_NAME_0=338;C;0;16;1;1;1;/home/kolan/dev/c/realloc_speed_test/realloc_speed_test_c.c;0
FILE_NAME_1=610;C++;0;16;1;1;1;/home/kolan/dev/c/realloc_speed_test/realloc_speed_test_cpp.cpp;0
[build-menu]
NF_00_LB=_Сделать

View File

@ -16,11 +16,10 @@ long_line_behaviour=1
long_line_column=72
[files]
current_page=2
FILE_NAME_0=0;Make;0;16;1;1;1;/home/kolan/dev/c/xalloc/Makefile;0
FILE_NAME_1=34;C;0;16;1;1;1;/home/kolan/dev/c/xalloc/xalloc_test.c;0
FILE_NAME_2=1225;C;0;16;1;1;1;/home/kolan/projects/include/xalloc.c;0
FILE_NAME_3=0;C;0;16;1;1;1;/home/kolan/projects/include/xalloc.h;0
current_page=1
FILE_NAME_0=381;C;0;16;1;1;1;/home/kolan/dev/c/xalloc/xalloc_test.c;0
FILE_NAME_1=1226;C;0;16;1;1;1;/home/kolan/projects/include/xalloc.c;0
FILE_NAME_2=2666;C;0;16;1;1;1;/home/kolan/projects/include/xalloc.h;0
[build-menu]
NF_00_LB=_Сделать

View File

@ -16,10 +16,10 @@ long_line_behaviour=1
long_line_column=72
[files]
current_page=0
FILE_NAME_0=611;C;0;16;1;1;1;/home/kolan/dev/c/zalloc/zalloc_test.c;0
FILE_NAME_1=1688;C;0;16;1;1;1;/home/kolan/projects/include/zalloc.c;0
FILE_NAME_2=0;C;0;16;1;1;1;/home/kolan/projects/include/zalloc.h;0
current_page=1
FILE_NAME_0=159;C;0;16;1;1;1;/home/kolan/dev/c/zalloc/zalloc_test.c;0
FILE_NAME_1=1115;C;0;16;1;1;1;/home/kolan/projects/include/zalloc.c;0
FILE_NAME_2=1060;C;0;16;1;1;1;/home/kolan/projects/include/zalloc.h;0
FILE_NAME_3=0;Make;0;16;1;1;1;/home/kolan/dev/c/zalloc/Makefile;0
[build-menu]

View File

@ -53,7 +53,7 @@ endif
%.o :
$(CC) -c $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ $<
zalloc_ext_test_obj = zalloc_ext.o zalloc.o xerror.o
zalloc_ext_test_obj = zalloc_ext.o zalloc.o xalloc.o xerror.o
zalloc_ext_test: zalloc_ext_test.o $(zalloc_ext_test_obj)
$(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDE) -o $@ zalloc_ext_test.o $(zalloc_ext_test_obj)
@ -63,6 +63,8 @@ zalloc_ext.o: $(KOLAN_INCLUDE)/zalloc_ext.c $(KOLAN_INCLUDE)/zalloc_ext.h
zalloc.o: $(KOLAN_INCLUDE)/zalloc.c $(KOLAN_INCLUDE)/zalloc.h
xalloc.o: $(KOLAN_INCLUDE)/xalloc.c $(KOLAN_INCLUDE)/xalloc.h
xerror.o: $(KOLAN_INCLUDE)/xerror.c $(KOLAN_INCLUDE)/xerror.c
clean:

View File

@ -16,11 +16,12 @@ long_line_behaviour=1
long_line_column=72
[files]
current_page=0
FILE_NAME_0=0;C;0;16;1;1;1;/home/kolan/dev/c/zalloc_ext/zalloc_test.c;0
FILE_NAME_1=1670;Make;0;16;1;1;1;/home/kolan/dev/c/zalloc_ext/Makefile;0
FILE_NAME_2=0;C;0;16;1;1;1;/home/kolan/projects/include/zalloc_ext.c;0
FILE_NAME_3=926;C;0;16;1;1;1;/home/kolan/projects/include/zalloc_ext.h;0
current_page=1
FILE_NAME_0=372;C;0;16;1;1;1;/home/kolan/dev/c/zalloc_ext/zalloc_ext_test.c;0
FILE_NAME_1=6576;C;0;16;1;1;1;/home/kolan/projects/include/zalloc_ext.c;0
FILE_NAME_2=0;C;0;16;1;1;1;/home/kolan/projects/include/xerror.h;0
FILE_NAME_3=2311;C;0;16;1;1;1;/home/kolan/projects/include/zalloc_ext.h;0
FILE_NAME_4=0;C;0;16;1;1;1;/home/kolan/projects/include/zalloc.h;0
[build-menu]
NF_00_LB=_Сделать

View File

@ -1,53 +1,57 @@
//~ kolan@nickolay-842 ~/dev/c/zalloc(default) $ time ./zalloc_test 50000 100000
//~ Success, iterations = 50000, nobj = 100000
//~
//~ real 0m0.246s
//~ user 0m0.110s
//~ sys 0m0.130s
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xalloc.h"
#include "zalloc.h"
#include "zalloc_ext.h"
#include "zalloc.h"
int main(int argc, char *argv[])
int main()
{
zalloc_append(0, NULL);
zalloc_append8(0, 0);
/* Duplicate functions
*/
void *zptr = zmalloc(384932);
void *zptr2 = zalloc_dup(zptr);
if (argc != 3) {
fputs("Usage: realloc_speed_test_cpp iterations nobj\n", stderr);
exit(-1);
}
void *arr = xmalloc(9832472);
void *zptr3 = zalloc_dup_usual(arr, 9832472);
void *zptr4_str = zalloc_dup_usual_str("Hello, world!");
size_t iterations = (size_t)atoi(argv[1]);
size_t nobj = (size_t)atoi(argv[2]);
void **p = zmalloc(sizeof(void *) * nobj);
memset(p, 0, sizeof(void *) * nobj);
size_t i, idx, sz;
for (i = 0; i < iterations; i++) {
idx = (size_t)(rand() % (int)nobj);
sz = i;
p[idx] = zrealloc(p[idx], sz);
if (sz && !p[idx]) {
fprintf(stderr, "Alloc error at i = %lu\n", i);
exit(-1);
}
}
for (i = 0; i < nobj; i++) {
zfree(p[i]);
p[i] = NULL;
}
printf("Success, iterations = %lu, nobj = %lu\n", iterations, nobj);
/* Append functions
*/
zptr = zalloc_append(zptr, zptr2);
zptr4_str = zalloc_append_str(zptr4_str, zptr4_str);
zptr2 = zalloc_append_usual(zptr2, arr, 9832472);
zptr4_str = zalloc_append_usual_str(zptr4_str, " - twice :)");
puts(zptr4_str);
//~ zalloc_append8(zdest, elem);
//~ zalloc_append8_str(zdest, elem);
//~ zalloc_append16(zdest, elem);
//~ zalloc_append16_str(zdest, elem);
//~ zalloc_append32(zdest, elem);
//~ zalloc_append32_str(zdest, elem);
//~ zalloc_append64(zdest, elem);
//~ zalloc_append64_str(zdest, elem);
//~
//~ /* Cut/Copy/Insert functions
//~ */
//~ zalloc_cut(zptr, off, len);
//~ zalloc_cut_str(zptr, off, len);
//~ zalloc_copy(zptr, off, len);
//~ zalloc_copy_str(zptr, off, len);
//~ zalloc_insert(zdest, off, zsrc);
//~ zalloc_insert_str(zdest, off, zsrc);
//~ zalloc_insert_usual(zdest, off, arr, len);
//~ zalloc_insert_usual_str(zdest, off, str);
//~ zalloc_insert8(zptr, off, elem);
//~ zalloc_insert8_str(zptr, off, elem);
//~ zalloc_insert16(zptr, off, elem);
//~ zalloc_insert16_str(zptr, off, elem);
//~ zalloc_insert32(zptr, off, elem);
//~ zalloc_insert32_str(zptr, off, elem);
//~ zalloc_insert64(zptr, off, elem);
//~ zalloc_insert64_str(zptr, off, elem);
return EXIT_SUCCESS;
}