more benchmarks
This commit is contained in:
parent
7598a93b31
commit
67a74f3417
|
@ -30,7 +30,9 @@ int main(int argc, char **argv) {
|
||||||
vm.return_stack_size = STACK_SIZE;
|
vm.return_stack_size = STACK_SIZE;
|
||||||
vm.stack_size = STACK_SIZE;
|
vm.stack_size = STACK_SIZE;
|
||||||
vm.memory_size = MEMORY_SIZE;
|
vm.memory_size = MEMORY_SIZE;
|
||||||
test_recursive_function_compile(vm.memory);
|
test_loop_compile(vm.memory);
|
||||||
|
/* test_add_function_compile(vm.memory); */
|
||||||
|
/* test_recursive_function_compile(vm.memory); */
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
emscripten_set_main_loop(mainloop, 0, 1);
|
emscripten_set_main_loop(mainloop, 0, 1);
|
||||||
|
|
|
@ -30,7 +30,7 @@ uint32_t test_loop_compile(Value *memory) {
|
||||||
memory[i++].f = 5.0f;
|
memory[i++].f = 5.0f;
|
||||||
memory[i++].u = OP(OP_ADD_REAL, 0, 0, 5); /* a += 5.0; */
|
memory[i++].u = OP(OP_ADD_REAL, 0, 0, 5); /* a += 5.0; */
|
||||||
memory[i++].u = OP(OP_ADD_INT, 1, 1, 3); /* (implied by loop) i = i + (-1) */
|
memory[i++].u = OP(OP_ADD_INT, 1, 1, 3); /* (implied by loop) i = i + (-1) */
|
||||||
memory[i++].u = OP(OP_JGT_INT, 4, 1, 2); /* } */
|
memory[i++].u = OP(OP_JGE_INT, 4, 1, 2); /* } */
|
||||||
memory[i++].u = OP(OP_REAL_TO_UINT, 1, 0, 0); /* let b = a as nat; */
|
memory[i++].u = OP(OP_REAL_TO_UINT, 1, 0, 0); /* let b = a as nat; */
|
||||||
memory[i++].u = OP(OP_READ_STRING, 2, 0, 0); /* let user_string = gets(); */
|
memory[i++].u = OP(OP_READ_STRING, 2, 0, 0); /* let user_string = gets(); */
|
||||||
memory[i++].u = OP(OP_UINT_TO_STRING, 3, 1, 0);
|
memory[i++].u = OP(OP_UINT_TO_STRING, 3, 1, 0);
|
||||||
|
|
4
src/vm.c
4
src/vm.c
|
@ -81,9 +81,7 @@ bool step_vm(VM *vm) {
|
||||||
return true;
|
return true;
|
||||||
case OP_RETURN:
|
case OP_RETURN:
|
||||||
vm->pc = vm->return_stack[--vm->rp].u; /* set pc to return address */
|
vm->pc = vm->return_stack[--vm->rp].u; /* set pc to return address */
|
||||||
Slice s = vm->frames[vm->fp].allocated; /* get allocated slice */
|
vm->mp = vm->frames[vm->fp--].allocated.start; /* reset memory pointer to start of old slice, pop the frame */
|
||||||
vm->fp--; /* pop the frame */
|
|
||||||
vm->mp = s.start; /* reset memory pointer to start of old slice */
|
|
||||||
return true;
|
return true;
|
||||||
case OP_LOADI:
|
case OP_LOADI:
|
||||||
vm->frames[vm->fp].registers[dest].i = vm->memory[vm->pc++].i;
|
vm->frames[vm->fp].registers[dest].i = vm->memory[vm->pc++].i;
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
function add(a, b)
|
||||||
|
return a + b
|
||||||
|
end
|
||||||
|
|
||||||
|
local sum = add(1, 1)
|
||||||
|
print(tostring(sum))
|
|
@ -0,0 +1,7 @@
|
||||||
|
sub add {
|
||||||
|
my ($a, $b) = @_;
|
||||||
|
return $a + $b;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $sum = add(1, 1);
|
||||||
|
print($sum . "\n");
|
|
@ -0,0 +1,5 @@
|
||||||
|
def add(a, b):
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
sum = add(1, 1)
|
||||||
|
print(str(sum))
|
|
@ -0,0 +1,6 @@
|
||||||
|
var add = Fn.new { |a, b|
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
var sum = add.call(1, 1)
|
||||||
|
System.print(sum.toString)
|
|
@ -0,0 +1,10 @@
|
||||||
|
local a = 5.0
|
||||||
|
for i = 5, 0, -1 do
|
||||||
|
a = a + 5.0
|
||||||
|
end
|
||||||
|
local b = math.floor(a)
|
||||||
|
io.write("Enter a string: ")
|
||||||
|
local user_string = io.read("*l")
|
||||||
|
print(tostring(a))
|
||||||
|
print(tostring(b))
|
||||||
|
print(user_string)
|
|
@ -0,0 +1,11 @@
|
||||||
|
my $a = 5.0;
|
||||||
|
for (my $i = 5; $i >= 0; $i--) {
|
||||||
|
$a += 5.0;
|
||||||
|
}
|
||||||
|
my $b = int($a);
|
||||||
|
print "Enter a string: ";
|
||||||
|
my $user_string = <STDIN>;
|
||||||
|
chomp($user_string);
|
||||||
|
print($a . "\n");
|
||||||
|
print($b . "\n");
|
||||||
|
print($user_string . "\n");
|
|
@ -0,0 +1,8 @@
|
||||||
|
a = 5.0
|
||||||
|
for i in range(5, -1, -1):
|
||||||
|
a += 5.0
|
||||||
|
b = int(a)
|
||||||
|
user_string = input("Enter a string: ")
|
||||||
|
print(str(a))
|
||||||
|
print(str(b))
|
||||||
|
print(user_string)
|
|
@ -0,0 +1,10 @@
|
||||||
|
var a = 5.0
|
||||||
|
var i = 5
|
||||||
|
while (i >= 0) {
|
||||||
|
a = a + 5.0
|
||||||
|
i = i - 1
|
||||||
|
}
|
||||||
|
var b = a
|
||||||
|
System.write("Enter a string: ")
|
||||||
|
System.print(a.toString)
|
||||||
|
System.print(b.toString)
|
|
@ -3,27 +3,35 @@
|
||||||
# Exit on error
|
# Exit on error
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Check if a filename was provided
|
||||||
|
if [ "$#" -ne 1 ]; then
|
||||||
|
echo "Usage: $0 <filename_without_extension>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILENAME=$1
|
||||||
|
|
||||||
# Function to print section headers
|
# Function to print section headers
|
||||||
print_section() {
|
print_section() {
|
||||||
printf '\n\e[1;34m%s\e[0m\n' "$1"
|
printf '\n\e[1;34m%s\e[0m\n' "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Wren Implementation
|
||||||
|
print_section "Wren ($FILENAME.wren)"
|
||||||
|
time wren "$FILENAME.wren"
|
||||||
|
|
||||||
# Lua Implementation
|
# Lua Implementation
|
||||||
print_section "Lua (fib.lua)"
|
print_section "Lua ($FILENAME.lua)"
|
||||||
time lua fib.lua
|
time lua "$FILENAME.lua"
|
||||||
|
|
||||||
# Perl Implementation
|
# Perl Implementation
|
||||||
print_section "Perl (fib.pl)"
|
print_section "Perl ($FILENAME.pl)"
|
||||||
time perl fib.pl
|
time perl "$FILENAME.pl"
|
||||||
|
|
||||||
# Python Implementation
|
# Python Implementation
|
||||||
print_section "Python (fib.py)"
|
print_section "Python ($FILENAME.py)"
|
||||||
time python3 fib.py
|
time python3 "$FILENAME.py"
|
||||||
|
|
||||||
# Wren Implementation
|
|
||||||
print_section "Wren (fib.wren)"
|
|
||||||
time wren fib.wren
|
|
||||||
|
|
||||||
# ZRE Implementation
|
# ZRE Implementation
|
||||||
print_section "zre (fib.zre)"
|
print_section "zre ($FILENAME.zre)"
|
||||||
time ../../src/zre #currently hardcoded
|
time ../../src/zre "$FILENAME.zre"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
main:
|
main:
|
||||||
loadi $0 23
|
loadi $0 35
|
||||||
pushi $0
|
pushi $0
|
||||||
call &fib
|
call &fib
|
||||||
popi $0
|
popi $0
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
real a = 5.0;
|
let a = 5.0;
|
||||||
do (int i = 5, 0, -1) {
|
do (let i = 5, 0, -1) {
|
||||||
a += 5.0;
|
a += 5.0;
|
||||||
}
|
}
|
||||||
nat b = a as nat;
|
let b = a as nat;
|
||||||
str user_string = readln();
|
let user_string = gets();
|
||||||
print(a.toS());
|
print(a.toS());
|
||||||
print(b.toS());
|
print(b.toS());
|
||||||
print(user_string);
|
print(user_string);
|
||||||
|
|
Loading…
Reference in New Issue