Skip to content

Commit

Permalink
Various fixes/updates
Browse files Browse the repository at this point in the history
* Show runtime at termination
* Show # of BR programs executed per second at termination
* Fix various off-by-one errors in evolution.c causing run failures
* Some small improvements to mutation routine
* Improve error logging
* Add -a option to penalize BF program length for entire evolution
  • Loading branch information
eriknyquist committed Oct 18, 2024
1 parent d170a01 commit d933d75
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 106 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DEBUG_FLAGS := -O0 -g3 -fsanitize=address,undefined
PROFILE_FLAGS := -O0 -g3 $(PROFILE_ENABLE_FLAGS)

CFLAGS := $(INCLUDES) -Wall -pedantic
.PHONY: clean
.PHONY: clean all debug profile output_dir x64_dir x86_dir windows_x64 windows_x86

all: CFLAGS += -O3
all: $(BUILD_OUTPUT)
Expand Down Expand Up @@ -61,5 +61,5 @@ windows_x86: $(BUILD_OUTPUT) x86_dir
cp $(BUILD_OUTPUT).exe $(X86_DIR)/$(PROGNAME).exe

clean:
[ -d $(OUTPUT_DIR) ] && rm -rf $(OUTPUT_DIR)
[ -d $(WIN_BUILD) ] && rm -rf $(WIN_BUILD)
rm -rf $(OUTPUT_DIR)
rm -rf $(WIN_BUILD)
28 changes: 14 additions & 14 deletions source/bf_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ char bf_rand_sym(void)
*/
int bf_rand_syms(char *output, int min_size, int max_size)
{
int size;

if (max_size < 0)
{
size = min_size;
}
else
{
size = randrange(min_size, max_size);
}

for (int i = 0; i < size; i++)
{
output[i] = bf_rand_sym();
int size;

if (max_size < 0)
{
size = min_size;
}
else
{
size = randrange(min_size, max_size);
}

for (int i = 0; i < size; i++)
{
output[i] = bf_rand_sym();
}

output[size] = 0;
Expand Down
33 changes: 29 additions & 4 deletions source/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ uint32_t pcg32_rand(void)
*/
uint32_t randrange(uint32_t low, uint32_t high)
{
return (pcg32_rand() % (high + 1u - low)) + low;
return (pcg32_rand() % (high + 1 - low)) + low;
}

/**
Expand All @@ -71,7 +71,7 @@ uint32_t randrange_except(uint32_t low, uint32_t high, uint32_t except)
*/
float randfloat(void)
{
return ((float)randrange(0u, 10000u)) / 10000.0f;
return ((float)randrange(0u, 10000u)) / 10000.0f;
}

/**
Expand Down Expand Up @@ -115,7 +115,7 @@ void hrsize (size_t size, char *buf, unsigned int bufsize)
/**
* @see common.h
*/
void hrcount (unsigned int size, char *buf, unsigned int bufsize)
void hrcount (uint64_t size, char *buf, unsigned int bufsize)
{
static const char names[NUMNAMES] =
{
Expand Down Expand Up @@ -180,11 +180,36 @@ static void timestamp(char *buf, int bufsize)
}
}

uint64_t ms_since_epoch(void)
{
#if WINDOWS
FILETIME ft;
LARGE_INTEGER li;

GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;

uint64_t ret = li.QuadPart;
ret -= 116444736000000000LL;
ret /= 10000;

#else
struct timeval tv;
gettimeofday(&tv, NULL);
uint64_t ret = tv.tv_usec;
ret /= 1000;
ret += (tv.tv_sec * 1000);
#endif

return ret;
}

/**
* @see common.h
*/
void bfi_log(const char* format, ...)
{
{
va_list args;
char tm[32];

Expand Down
7 changes: 6 additions & 1 deletion source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ void hrsize (size_t size, char *buf, unsigned int bufsize);
* @param buf pointer to location where output should be written
* @param bufsize maximum number of output characters
*/
void hrcount (unsigned int size, char *buf, unsigned int bufsize);
void hrcount (uint64_t size, char *buf, unsigned int bufsize);

/**
* Gets the number of milliseconds since the UNIX epoch
*/
uint64_t ms_since_epoch(void);

/**
* Logs a formatted string
Expand Down
Loading

0 comments on commit d933d75

Please sign in to comment.