Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wall time (not CPU time) in dotproduct bench #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions u3_interpreters/concur/vec/tests.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "vendor/unity.h"

#include <sys/time.h>
#include "vec.h"

extern data_t dotproduct(vec_ptr, vec_ptr);
Expand Down Expand Up @@ -49,15 +50,17 @@ void test_longer(void) {

long expected = (2 * n * n * n + 3 * n * n + n) / 6;

clock_t start = clock();
struct timeval start, stop;
gettimeofday(&start, NULL);
long actual = dotproduct(u, v);
clock_t end = clock();
gettimeofday(&stop, NULL);


TEST_ASSERT_EQUAL(expected, actual);
double time_elapsed = (end - start) / (double)CLOCKS_PER_SEC;
double elapsed = stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec) / 1000000.0;
printf(
"%0.2fs to take product of length %ld vectors (%0.2f ns per element)\n",
time_elapsed, n, time_elapsed * 1e9 / n);
elapsed, n, elapsed * 1e9 / n);

free_vec(u);
free_vec(v);
Expand Down