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.stack_size = STACK_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__
|
||||
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++].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_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_READ_STRING, 2, 0, 0); /* let user_string = gets(); */
|
||||
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;
|
||||
case OP_RETURN:
|
||||
vm->pc = vm->return_stack[--vm->rp].u; /* set pc to return address */
|
||||
Slice s = vm->frames[vm->fp].allocated; /* get allocated slice */
|
||||
vm->fp--; /* pop the frame */
|
||||
vm->mp = s.start; /* reset memory pointer to start of old slice */
|
||||
vm->mp = vm->frames[vm->fp--].allocated.start; /* reset memory pointer to start of old slice, pop the frame */
|
||||
return true;
|
||||
case OP_LOADI:
|
||||
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
|
||||
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
|
||||
print_section() {
|
||||
printf '\n\e[1;34m%s\e[0m\n' "$1"
|
||||
}
|
||||
|
||||
# Wren Implementation
|
||||
print_section "Wren ($FILENAME.wren)"
|
||||
time wren "$FILENAME.wren"
|
||||
|
||||
# Lua Implementation
|
||||
print_section "Lua (fib.lua)"
|
||||
time lua fib.lua
|
||||
print_section "Lua ($FILENAME.lua)"
|
||||
time lua "$FILENAME.lua"
|
||||
|
||||
# Perl Implementation
|
||||
print_section "Perl (fib.pl)"
|
||||
time perl fib.pl
|
||||
print_section "Perl ($FILENAME.pl)"
|
||||
time perl "$FILENAME.pl"
|
||||
|
||||
# Python Implementation
|
||||
print_section "Python (fib.py)"
|
||||
time python3 fib.py
|
||||
|
||||
# Wren Implementation
|
||||
print_section "Wren (fib.wren)"
|
||||
time wren fib.wren
|
||||
print_section "Python ($FILENAME.py)"
|
||||
time python3 "$FILENAME.py"
|
||||
|
||||
# ZRE Implementation
|
||||
print_section "zre (fib.zre)"
|
||||
time ../../src/zre #currently hardcoded
|
||||
print_section "zre ($FILENAME.zre)"
|
||||
time ../../src/zre "$FILENAME.zre"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
main:
|
||||
loadi $0 23
|
||||
loadi $0 35
|
||||
pushi $0
|
||||
call &fib
|
||||
popi $0
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
real a = 5.0;
|
||||
do (int i = 5, 0, -1) {
|
||||
let a = 5.0;
|
||||
do (let i = 5, 0, -1) {
|
||||
a += 5.0;
|
||||
}
|
||||
nat b = a as nat;
|
||||
str user_string = readln();
|
||||
let b = a as nat;
|
||||
let user_string = gets();
|
||||
print(a.toS());
|
||||
print(b.toS());
|
||||
print(user_string);
|
||||
|
|
Loading…
Reference in New Issue