[quiz][ion/test] Move time measurements to quiz

to be able to do measurements in any test
This commit is contained in:
Ruben Dashyan
2020-02-14 16:32:21 +01:00
committed by Émilie Feral
parent 068ed96d79
commit bc0b21463e
9 changed files with 78 additions and 59 deletions

View File

@@ -14,6 +14,7 @@ runner_src += $(addprefix quiz/src/, \
assertions.cpp \
i18n.cpp \
runner.cpp \
stopwatch.cpp \
)
runner_src += $(BUILD_DIR)/quiz/src/tests_symbols.c

View File

@@ -0,0 +1,17 @@
#ifndef QUIZ_STOPWATCH_H
#define QUIZ_STOPWATCH_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
uint64_t quiz_stopwatch_start();
void quiz_stopwatch_print_lap(uint64_t startTime);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,8 +1,6 @@
#include "quiz.h"
#include "symbols.h"
#include <string.h>
#include <ion.h>
#include <kandinsky.h>
#include <poincare/init.h>
#include <poincare/tree_pool.h>
#include <poincare/exception_checkpoint.h>

36
quiz/src/stopwatch.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include <quiz/stopwatch.h>
#include "quiz.h"
#include <ion/timing.h>
#include <string.h>
uint64_t quiz_stopwatch_start() {
return Ion::Timing::millis();
}
static size_t uint64ToString(uint64_t n, char buffer[]) {
size_t len = 0;
do {
buffer[len++] = (n % 10) + '0';
} while ((n /= 10) > 0);
int i = 0;
int j = len - 1;
while (i < j) {
char c = buffer[i];
buffer[i++] = buffer[j];
buffer[j--] = c;
}
return len;
}
void quiz_stopwatch_print_lap(uint64_t startTime) {
constexpr char Time[] = " time: ";
constexpr char Ms[] = "ms";
constexpr size_t uint64ToStringMaxLength = 20;
constexpr size_t MaxLength = sizeof(Time) + uint64ToStringMaxLength + sizeof(Ms) + 1;
char buffer[MaxLength];
char * position = buffer;
position += strlcpy(position, Time, sizeof(Time));
position += uint64ToString(Ion::Timing::millis() - startTime, position);
position += strlcpy(position, Ms, sizeof(Ms));
quiz_print(buffer);
}