-
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
1 parent
740c073
commit 4579582
Showing
10 changed files
with
111 additions
and
33 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
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,71 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use lykiadb_lang::{parser::{program::Program, resolver::Resolver, Parser}, tokenizer::scanner::Scanner, Locals, Scopes}; | ||
use rustc_hash::FxHashMap; | ||
|
||
pub struct ParserBenchmark { | ||
scopes: Scopes, | ||
locals: Locals, | ||
} | ||
|
||
|
||
impl ParserBenchmark { | ||
pub fn new() -> ParserBenchmark { | ||
ParserBenchmark { | ||
scopes: vec![], | ||
locals: FxHashMap::default(), | ||
} | ||
} | ||
|
||
pub fn process(&mut self, source: &str) -> Program { | ||
let tokens = Scanner::scan(source).unwrap(); | ||
let mut program = Parser::parse(&tokens).unwrap(); | ||
let mut resolver = Resolver::new(self.scopes.clone(), &program, Some(self.locals.clone())); | ||
let (scopes, locals) = resolver.resolve().unwrap(); | ||
|
||
self.scopes = scopes; | ||
self.locals.clone_from(&locals); | ||
program.set_locals(self.locals.clone()); | ||
|
||
program | ||
} | ||
} | ||
|
||
fn runtime() { | ||
let content: String = " | ||
SELECT * FROM books b | ||
INNER JOIN | ||
( | ||
categories c | ||
INNER JOIN | ||
publishers AS p | ||
ON b.category_id = c.id | ||
) | ||
ON b.publisher_id = p.id | ||
WHERE p.name = 'Springer' | ||
UNION | ||
SELECT * FROM books | ||
INTERSECT | ||
SELECT * FROM books | ||
EXCEPT | ||
SELECT * FROM books; | ||
".to_string(); | ||
let mut parser = black_box(ParserBenchmark::new()); | ||
black_box(parser.process(black_box(&content))); | ||
} | ||
|
||
fn bench(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("sample-size-example"); | ||
group.bench_function("2-way join", |b| { | ||
b.iter(|| runtime()) | ||
}); | ||
group.finish(); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default(); | ||
targets = bench | ||
} | ||
|
||
criterion_main!(benches); |
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,7 +1,7 @@ | ||
// Define recursive Fibonacci function | ||
function fib($n) { | ||
function $fib($n) { | ||
if ($n < 2) return $n; | ||
return fib($n - 2) + fib($n - 1); | ||
return $fib($n - 2) + $fib($n - 1); | ||
}; | ||
|
||
fib(35); | ||
$fib(35); |
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,3 @@ | ||
var $a = {}; | ||
$a.test = 100; | ||
print($a); | ||
io::print($a); |
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,13 +1,13 @@ | ||
// Define recursive Fibonacci function | ||
function fib($n) { | ||
function $fib($n) { | ||
if ($n < 2) return $n; | ||
return fib($n - 2) + fib($n - 1); | ||
return $fib($n - 2) + $fib($n - 1); | ||
}; | ||
|
||
var $start_ly = time::clock(); | ||
print(fib(35) == 9227465); | ||
print("elapsed (user defined):", time::clock() - $start_ly); | ||
io::print($fib(35) == 9227465); | ||
io::print("elapsed (user defined):", time::clock() - $start_ly); | ||
|
||
var $start_rs = time::clock(); | ||
print(Benchmark.fib(35) == 9227465); | ||
print("elapsed (native):", time::clock() - $start_rs); | ||
io::print(Benchmark::fib(35) == 9227465); | ||
io::print("elapsed (native):", time::clock() - $start_rs); |
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,20 +1,20 @@ | ||
function helloWorld ($message) { | ||
print("Hello world!", $message); | ||
function $hello_world($message) { | ||
io::print("Hello world!", $message); | ||
{ | ||
{ | ||
return "and returning from here."; | ||
{ | ||
print("inner"); | ||
print("inner"); | ||
print("inner"); | ||
io::print("inner"); | ||
io::print("inner"); | ||
io::print("inner"); | ||
} | ||
print("outer"); | ||
print("outer"); | ||
print("outer"); | ||
io::print("outer"); | ||
io::print("outer"); | ||
io::print("outer"); | ||
} | ||
} | ||
}; | ||
|
||
for (var $i = 0; $i < 10; $i = $i + 1) { | ||
print(helloWorld("My name is Lykia.")); | ||
io::print($hello_world("My name is Lykia.")); | ||
} |
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,12 +1,12 @@ | ||
function makeCounter() { | ||
function $make_counter() { | ||
var $i = 0; | ||
function count() { | ||
function $count() { | ||
$i = $i + 1; | ||
print($i); | ||
io::print($i); | ||
}; | ||
|
||
return count; | ||
return $count; | ||
}; | ||
var $count = makeCounter(); | ||
var $count = $make_counter(); | ||
$count(); | ||
$count(); |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Define recursive Fibonacci function | ||
function fib($n) { | ||
function $fib($n) { | ||
if ($n < 2) return $n; | ||
return fib($n - 2) + fib($n - 1); | ||
return $fib($n - 2) + $fib($n - 1); | ||
}; | ||
|
||
117E |
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