feat: add benchmark runner with fib implementations and OS.clock primitive
Add a benchmark runner script (benchmark/run_all) that executes multiple fibonacci implementations across languages (Lua, Python, Ruby, Wren) and computes mean, median, and standard deviation from 7 runs. Update existing fib benchmarks to loop 5 times at fib(30) with elapsed timing. Introduce OS.clock primitive in C core and OS class to support timing in Wren. Adjust number formatting to "%.14g" for consistent output precision.
This commit is contained in:
+13
-2
@@ -2,6 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "compiler.h"
|
||||
#include "primitives.h"
|
||||
@@ -93,7 +94,7 @@ DEF_PRIMITIVE(num_toString)
|
||||
{
|
||||
// TODO(bob): What size should this be?
|
||||
char temp[100];
|
||||
sprintf(temp, "%g", AS_NUM(args[0]));
|
||||
sprintf(temp, "%.14g", AS_NUM(args[0]));
|
||||
return (Value)newString(vm, temp, strlen(temp));
|
||||
}
|
||||
|
||||
@@ -235,6 +236,12 @@ DEF_PRIMITIVE(io_write)
|
||||
return args[1];
|
||||
}
|
||||
|
||||
DEF_PRIMITIVE(os_clock)
|
||||
{
|
||||
double time = (double)clock() / CLOCKS_PER_SEC;
|
||||
return NUM_VAL(time);
|
||||
}
|
||||
|
||||
static const char* CORE_LIB =
|
||||
"class Object {}\n"
|
||||
"class Bool {}\n"
|
||||
@@ -244,7 +251,8 @@ static const char* CORE_LIB =
|
||||
"class Null {}\n"
|
||||
"class String {}\n"
|
||||
"class IO {}\n"
|
||||
"var io = IO.new\n";
|
||||
"var io = IO.new\n"
|
||||
"class OS {}\n";
|
||||
|
||||
void loadCore(VM* vm)
|
||||
{
|
||||
@@ -301,6 +309,9 @@ void loadCore(VM* vm)
|
||||
ObjClass* ioClass = AS_CLASS(findGlobal(vm, "IO"));
|
||||
PRIMITIVE(ioClass, "write ", io_write);
|
||||
|
||||
ObjClass* osClass = AS_CLASS(findGlobal(vm, "OS"));
|
||||
PRIMITIVE(osClass->metaclass, "clock", os_clock);
|
||||
|
||||
ObjClass* unsupportedClass = newClass(vm, vm->objectClass);
|
||||
|
||||
// TODO(bob): Make this a distinct object type.
|
||||
|
||||
@@ -1031,7 +1031,7 @@ void printValue(Value value)
|
||||
#ifdef NAN_TAGGING
|
||||
if (IS_NUM(value))
|
||||
{
|
||||
printf("%g", AS_NUM(value));
|
||||
printf("%.14g", AS_NUM(value));
|
||||
}
|
||||
else if (IS_OBJ(value))
|
||||
{
|
||||
@@ -1059,7 +1059,7 @@ void printValue(Value value)
|
||||
{
|
||||
case VAL_FALSE: printf("false"); break;
|
||||
case VAL_NULL: printf("null"); break;
|
||||
case VAL_NUM: printf("%g", AS_NUM(value)); break;
|
||||
case VAL_NUM: printf("%.14g", AS_NUM(value)); break;
|
||||
case VAL_TRUE: printf("true"); break;
|
||||
case VAL_OBJ:
|
||||
switch (value.obj->type)
|
||||
|
||||
Reference in New Issue
Block a user