-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "lib/googletest"] | ||
path = lib/googletest | ||
url = https://github.com/google/googletest | ||
[submodule "lib/benchmark"] | ||
path = lib/benchmark | ||
url = [email protected]:google/benchmark.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ sudo apt install g++ cmake libffi-dev | |
Compile Banana: | ||
|
||
``` | ||
git clone --recurse-submodules [email protected]:omaraflak/banana.git | ||
cd banana | ||
cmake . | ||
make | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <benchmark/benchmark.h> | ||
#include "../src/lib/ast.h" | ||
#include "../src/lib/vm.h" | ||
#include "../src/lib/instructions.h" | ||
#include "../src/lib/fileutils.h" | ||
#include "../src/lib/scanner.h" | ||
#include "../src/lib/parser.h" | ||
|
||
#define PATH(name) "benchmarks/" #name ".na" | ||
|
||
#define NA_BENCHMARK(name) \ | ||
static void bm_##name(benchmark::State &state) { \ | ||
auto content = fileutils::read_string(PATH(name)); \ | ||
auto tokens = scanner::scan(content.c_str()); \ | ||
auto tree = parser::parse(tokens); \ | ||
auto instructions = ast::to_instructions(tree); \ | ||
auto bytes = Instruction::to_bytes(instructions); \ | ||
for (auto _ : state) { \ | ||
Vm(bytes).execute(); \ | ||
} \ | ||
} \ | ||
BENCHMARK(bm_##name) \ | ||
|
||
NA_BENCHMARK(fib); | ||
NA_BENCHMARK(primes); | ||
|
||
// Run the benchmark | ||
BENCHMARK_MAIN(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
long fib(long n) { | ||
if (n == 1 or n == 2) { | ||
return n; | ||
} | ||
return fib(n - 1) + fib(n - 2); | ||
} | ||
|
||
fib(20); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
long isprime(long n) { | ||
for (long i = 2; i < n; i++) { | ||
if (n % i == 0) { | ||
return 0; | ||
} | ||
} | ||
return 1; | ||
} | ||
|
||
long main() { | ||
long n = 1000; | ||
long i = 3; | ||
while (n > 1) { | ||
if (isprime(i) == 1) { | ||
n--; | ||
} | ||
i += 2; | ||
} | ||
} |