Commit 9359272d authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

add nfib example + correct measurement of execution time in DEBUG mode

parent a115c3ab
......@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <sys/time.h>
#include "getline.h"
......@@ -18,7 +19,7 @@ int main ( int argc, char *argv[] )
init_desc();
init_prim();
char* input = "..\\tests\\Braun.bsapl";
char* input = "..\\tests\\nfib.bsapl";
if ( argc == 2 )
{
......@@ -62,11 +63,26 @@ int main ( int argc, char *argv[] )
Code* expr = parseTerm(&exprstream);
#ifdef DEBUG
struct timeval t1, t2;
gettimeofday(&t1, NULL);
#endif
Thunk* res = exec(expr, stack_top_a, NULL, true);
eval(res);
#ifdef DEBUG
gettimeofday(&t2, NULL);
#endif
print(res, true);
#ifdef DEBUG
// compute and print the elapsed time in millisec
double elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
printf("\n\nexecution time: %G ms\n", elapsedTime);
print_stat();
#endif
}
......@@ -16,7 +16,7 @@ Thunk* stack_a[STACK_SIZE_A];
char* heap_start;
void print_stat() {
printf("\n\nallocation:\n");
printf("\nallocation:\n");
printf("desc: %d\n", desc_alloc);
printf("code: %d\n", code_alloc);
printf("heap: %d (%d thunks)\n", heap_alloc, nr_heap_alloc);
......
[2692537]
\ No newline at end of file
main = example.Start
example.Start = example.nfib 30
example.nfib !n_0 = if (lt n_0 2) 1 (add 1 (add (example.nfib (sub n_0 1)) (example.nfib (sub n_0 2))))
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