Commit 2e2f8caa authored by Mol Thomas Folkert's avatar Mol Thomas Folkert
Browse files

early null_and_bounds test, C counterpart

parents
null_and_bounds
*.gch
CC = clang
CCFLAGS = -O3
TARGET = null_and_bounds
DEP = null_and_bounds_externals.h
all: $(TARGET)
$(TARGET): null_and_bounds.c
$(CC) $(CCFLAGS) null_and_bounds_externals.h
$(CC) $(CCFLAGS) null_and_bounds.c -o $@
#include <time.h>
#include <stdio.h>
#include "null_and_bounds_externals.h"
int comptime()
{
int lo = 0;
int hi = 14000;
int arr[14000] = {0};
int tmp = 0;
for (int i = lo; i < hi; ++i)
tmp += arr[i];
return tmp;
}
int volhiarr()
{
int lo = 0;
volatile int hi = 14000;
volatile int arr[14000] = {0};
int tmp = 0;
for (int i = lo; i < hi; ++i)
tmp += arr[i];
return tmp;
}
int passed(int lo, int hi, int arr[])
{
int tmp = 0;
for (int i = lo; i < hi; ++i)
tmp += arr[i];
return tmp;
}
int externals()
{
int tmp = 0;
for (int i = external_lo; i < external_hi; ++i)
tmp += external_arr[i];
return tmp;
}
int hi_fun()
{
return 14000;
}
int funarr[14000] = {0};
int *arr_fun(int i)
{
funarr[i] *= -1;
return funarr;
}
int funhiarr(int (*hifun)(), int *(*arrfun)(int))
{
int lo = 0;
int tmp = 0;
for (int i = lo; i < (*hifun)(); ++i)
tmp += (*arrfun)(i)[i];
return tmp;
}
int main()
{
clock_t comptime_start = clock();
int comptime_res = comptime();
double comptime_time = (double)(clock() - comptime_start) / CLOCKS_PER_SEC;
printf("Comptime done! Time: %f Result: %i\n", comptime_time, comptime_res);
clock_t volhiarr_start = clock();
int volhiarr_res = volhiarr();
double volhiarr_time = (double)(clock() - volhiarr_start) / CLOCKS_PER_SEC;
printf("Volhiarr done! Time: %f Result: %i\n", volhiarr_time, volhiarr_res);
clock_t externals_start = clock();
int externals_res = externals();
double externals_time = (double)(clock() - externals_start) / CLOCKS_PER_SEC;
printf("Externals done! Time: %f Result: %i\n", externals_time, externals_res);
clock_t funhiarr_start = clock();
int funhiarr_res = funhiarr(&hi_fun, &arr_fun);
double funhiarr_time = (double)(clock() - funhiarr_start) / CLOCKS_PER_SEC;
printf("Funhiarr done! Time: %f Result: %i\n", funhiarr_time, funhiarr_res);
double overall_time = (double)(clock() - comptime_start) / CLOCKS_PER_SEC;
printf("Overall time: %f\n", overall_time);
}
int external_lo = 0;
int external_hi = 14000;
int external_arr[14000] = {0};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment