-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #973 from hash-org/lexer-improvements
- Loading branch information
Showing
40 changed files
with
1,364 additions
and
872 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 @@ | ||
//! Some Hash lexer benchmarks. | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; | ||
use hash_lexer::Lexer; | ||
use hash_source::{location::SpannedSource, SourceId}; | ||
|
||
static IDENTIFIERS: &str = "It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton \ | ||
It was the year when they finally immanentized the Eschaton"; | ||
|
||
static KEYWORDS: &str = "for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type \ | ||
for while loop if else match as in trait enum struct continue break return import raw false unsafe pub priv mut mod impl true type"; | ||
|
||
static MIX: &str = "for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct \ | ||
for it was in the year as they finally immanentized the enum Eschaton while struct"; | ||
|
||
/// Test candidates that are to be run. | ||
static CANDIDATES: [(&str, &str); 3] = | ||
[("identifiers", IDENTIFIERS), ("mixed", MIX), ("keywords", KEYWORDS)]; | ||
|
||
fn lex(source: &str) { | ||
let mut lexer = Lexer::new(SpannedSource(source), SourceId::default()); | ||
|
||
while let Some(token) = lexer.advance_token() { | ||
black_box(token); | ||
} | ||
} | ||
|
||
fn bench_idents(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("idents"); | ||
|
||
for (name, source) in CANDIDATES { | ||
group.throughput(Throughput::Bytes(source.len() as u64)); | ||
group.bench_with_input(name, &source, |b, &s| b.iter(|| lex(s))); | ||
} | ||
} | ||
|
||
criterion_group!(benches, bench_idents); | ||
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
Oops, something went wrong.