Commit c304af5e authored by Mol Thomas Folkert's avatar Mol Thomas Folkert
Browse files

templates for function tests

parent e81f1557
/// Header to be included in source, verbatim
/// No arguments.
/// No arguments. (Do NOT use formatted print.)
const C_HEADER =
\\#include <stdio.h>
\\#include <stdint.h>
\\#include <time.h>
\\
;
const ZIG_HEADER = "";
const ZIG_HEADER =
\\const std = @import("std");
\\const ctime = @cImport({
\\ @cInclude("time.h");
\\});
\\
;
/// General loop template used in below templates
/// Argument index:
......@@ -185,3 +192,31 @@ const ZIG_FUNCTION_LOOP_TEMPLATE =
\\}}
\\
;
/// General testing template for running a function and printing its duration.
/// Include inside a function body.
/// Argument index:
/// 0 (string) = function name (to test)
const C_TEST_FUNCTION_TEMPLATE =
\\ struct timespec {0s}_start;
\\ struct timespec {0s}_end;
\\ clock_gettime(CLOCK_MONOTONIC_RAW, &{0s}_start);
\\ {0s}();
\\ clock_gettime(CLOCK_MONOTONIC_RAW, &{0s}_end);
\\ double {0s}_duration = {0s}_end.tv_nsec - {0s}_start.tv_nsec;
\\ printf("{0s} done. Time: %d\n.", {0s}_duration);
\\
;
const ZIG_TEST_FUNCTION_TEMPLATE =
\\ const stdout = std.io.getStdOut().writer();
\\
\\ ctime.timespec {0s}_start;
\\ ctime.timespec {0s}_end;
\\ ctime.clock_gettime(ctime.CLOCK_MONOTONIC_RAW, &{0s}_start);
\\ {0s}();
\\ ctime.clock_gettime(ctime.CLOCK_MONOTONIC_RAW, &{0s}_end);
\\ var {0s}_duration: f64 = {0s}_end.tv_nsec - {0s}_start.tv_nsec;
\\ try stdout.print("{0s} done. Time: %d\n.", {0s}_duration);
\\
;
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