<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "rtAllocator.h"

#define NUMALLOCS 1000000

int   sizes[NUMALLOCS];
void* allocs[NUMALLOCS];

void*   blockalloc(long size) {
	return malloc(size);
}
void*   blockrealloc(void* fp, long newsize) {
	return realloc(fp, newsize);
} 
void    blockfree(void* p) {
	free(p);
}

typedef void* (MallocFunc)(size_t size);
typedef void  (FreeFunc)(void* p);

void init() {
  for (int i = 0; i < NUMALLOCS; i++) {
		sizes[i] = (((double)rand()/(double)RAND_MAX) * 128);
	}
}

void test(MallocFunc afunc, FreeFunc ffunc) {

	for (int i = 0; i < 10; i++) {
		// Alloc all
		for (int j = 0; j < NUMALLOCS; j++) {
			allocs[j] = afunc(sizes[j]);
		}
#if 1
		// Free first half
		for (int j = 0; j < NUMALLOCS/2; j++) {
			ffunc(allocs[j]);
		}
		// Alloc first half
		for (int j = 0; j < NUMALLOCS/2; j++) {
			allocs[j] = afunc(sizes[j]);
		}
		// Free second half
		for (int j = NUMALLOCS/2; j < NUMALLOCS; j++) {
			ffunc(allocs[j]);
		}
		// Alloc second half
		for (int j = NUMALLOCS/2; j < NUMALLOCS; j++) {
			allocs[j] = afunc(sizes[j]);
		}
#endif
		// Free all
		for (int j = 0; j < NUMALLOCS; j++) {
			ffunc(allocs[j]);
		}

	}

}

int  main() {

#include <stdint.h>
#if UINTPTR_MAX == 0xffffffff
	/* 32-bit */
	printf("32bit\n");
#elif UINTPTR_MAX == 0xffffffffffffffff
	/* 64-bit */
	printf("64bit\n");
#else
	/* wtf */
	printf("wtf\n");
#endif

	void* p;
	printf("ptr size %lu\n", sizeof(p));
	init();

#if 1
	for (int i=0; i < 5; i++) {
	clock_t start1 = clock();
	test(rtAllocator::alloc, rtAllocator::free);
	clock_t end1 = clock();
	double delta = (end1-start1)/(double)CLOCKS_PER_SEC;
	printf("rtAllocator time: %f\n", delta);
	}
#endif
	{
	clock_t start2 = clock();
	test(malloc, free);
	clock_t end2 = clock();
	double delta2 = (end2-start2)/(double)CLOCKS_PER_SEC;
	printf("malloc/free time: %f\n", delta2);
	}
	return 0;
}<commit_msg>Test Cleanup<commit_after>// Copyright 2006-2013 <NAME>
// MIT License

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "rtAllocator.h"

#define NUMALLOCS 10000

int   sizes[NUMALLOCS];
void* allocs[NUMALLOCS];

typedef void* (MallocFunc)(size_t size);
typedef void  (FreeFunc)(void* p);

void init() {
  for (int i = 0; i < NUMALLOCS; i++) {
		sizes[i] = (((double)rand()/(double)RAND_MAX) * ((double)rand()/(double)RAND_MAX) * ((double)rand()/(double)RAND_MAX) * 
		((double)rand()/(double)RAND_MAX) * ((double)rand()/(double)RAND_MAX) * ((double)rand()/(double)RAND_MAX) * ((double)rand()/(double)RAND_MAX) * 1024);
	}
}

void test(MallocFunc afunc, FreeFunc ffunc) {

	for (int i = 0; i < 1000; i++) {

		// Alloc all
			for (int j = 0; j < NUMALLOCS; j++) {
				allocs[j] = afunc(sizes[j]);
			}

#if 1
		// Free first half
		for (int j = 0; j < NUMALLOCS/2; j++) {
			ffunc(allocs[j]);
		}
		// Alloc first half
		for (int j = 0; j < NUMALLOCS/2; j++) {
			allocs[j] = afunc(sizes[j]);
		}
		// Free second half
		for (int j = NUMALLOCS/2; j < NUMALLOCS; j++) {
			ffunc(allocs[j]);
		}
		// Alloc second half
		for (int j = NUMALLOCS/2; j < NUMALLOCS; j++) {
			allocs[j] = afunc(sizes[j]);
		}
#endif

			for (int j = 0; j < NUMALLOCS; j++) {
				ffunc(allocs[j]);
			}

	}

}

int  main() {

	init();

	for (int i=0; i < 3; i++) {
		clock_t start1 = clock();
		test(rtAllocator::alloc, rtAllocator::free);
		clock_t end1 = clock();
		double delta = (end1-start1)/(double)CLOCKS_PER_SEC;
		printf("rtAllocator time: %f\n", delta);
	}

	for (int i=0; i < 3; i++)
	{
		clock_t start2 = clock();
		test(malloc, free);
		clock_t end2 = clock();
		double delta2 = (end2-start2)/(double)CLOCKS_PER_SEC;
		printf("malloc/free time: %f\n", delta2);
	}

	return 0;
}
{'fraction_non_alphanumeric': 0.19574009166891346, 'fraction_numerical': 0.025343758425451605, 'mean_word_length': 3.5024271844660193, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1155250', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1562, 'n_words': 375}