Skip to content

Commit 2a4dc64

Browse files
committed
Review README and benchmarks
1 parent 6c34f9c commit 2a4dc64

File tree

4 files changed

+45
-23
lines changed

4 files changed

+45
-23
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ members = [
1313
[profile.release]
1414
lto = "fat"
1515
codegen-units = 1
16+
debug = true

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,29 @@ to Rust to manage the language in Rust.
202202
## V0
203203

204204
In V0, transpilation is a direct style generation of Parsec without any
205-
optimisations. To this end, the `AST` is translated directly into a parser
206-
parser using the `core` library.
205+
optimisations. To this end, the `AST` is translated directly into a parser
206+
using the `core` library.
207207
cf. [celma parser in direct style](https://github.com/d-plaindoux/celma/blob/master/lang/v0/parser/src/parser.rs).
208208

209209
### Benchmarks
210210

211-
Material:
211+
- Material: MacBookPro Apple M2 Max 64G
212+
- [Samples](https://github.com/d-plaindoux/celma/blob/master/lang/v0/macro/benches/data/) used for the benchmarks.
212213

213-
```sh
214-
test json_apache ... bench: 1,652,349 ns/iter (+/- 119,721) = 75 MB/s
215-
test json_canada_nom ... bench: 135,309 ns/iter (+/- 4,034) = 68 MB/s
216-
test json_canada_pest ... bench: 61,084,354 ns/iter (+/- 2,746,834) = 36 MB/s
217-
test json_data ... bench: 133,788 ns/iter (+/- 10,607) = 69 MB/s
214+
#### HTTP Header
215+
216+
```shell
217+
test http_data ... bench: 11,845 ns/iter (+/- 382) = 65 MB/s
218218
```
219219

220+
#### JSON
221+
222+
```shell
223+
test json_apache ... bench: 1,560,412 ns/iter (+/- 21,383) = 87 MB/s
224+
test json_canada_nom ... bench: 127,925 ns/iter (+/- 15,263) = 82 MB/s
225+
test json_canada_pest ... bench: 57,397,799 ns/iter (+/- 3,442,455) = 43 MB/s
226+
test json_data ... bench: 126,348 ns/iter (+/- 5,283) = 81 MB/s
227+
```
220228

221229
## V1
222230

lang/v0/macro/benches/http.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
use bencher::{Bencher, benchmark_group, benchmark_main, black_box};
16+
use bencher::{benchmark_group, benchmark_main, black_box, Bencher};
1717
use celma_v0_core::parser::and::AndOperation;
1818
use celma_v0_core::parser::char::{alpha, digit};
1919
use celma_v0_core::parser::core::eos;
2020
use celma_v0_core::parser::response::Response::{Reject, Success};
2121
use celma_v0_core::parser::specs::Parse;
22-
use celma_v0_core::stream::char_stream::CharStream;
22+
use celma_v0_core::stream::array_stream::ArrayStream;
2323
use celma_v0_core::stream::position::Position;
2424
use celma_v0_core::stream::specs::Stream;
2525
use celma_v0_macro::parsec_rules;
@@ -45,13 +45,14 @@ parsec_rules!(
4545
// -------------------------------------------------------------------------------------------------
4646

4747
fn http_data(b: &mut Bencher) {
48-
let data = include_str!("data/request.http");
48+
let vec = include_str!("data/request.http").chars().collect::<Vec<char>>();
49+
let data = vec.as_slice();
4950
b.bytes = data.len() as u64;
5051
parse(b, data)
5152
}
5253

53-
fn parse(b: &mut Bencher, buffer: &str) {
54-
let stream = CharStream::new_with_position(buffer, <usize>::new());
54+
fn parse(b: &mut Bencher, buffer: &[char]) {
55+
let stream = ArrayStream::new_with_position(buffer, <usize>::new());
5556

5657
b.iter(|| {
5758
let response = http_header()

lang/v0/macro/benches/json.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
#[macro_use]
1818
extern crate bencher;
1919

20-
use bencher::{Bencher, black_box};
20+
use bencher::{black_box, Bencher};
2121

2222
use celma_v0_core::parser::and::AndOperation;
2323
use celma_v0_core::parser::char::{digit, space};
2424
use celma_v0_core::parser::core::eos;
2525
use celma_v0_core::parser::literal::delimited_string;
2626
use celma_v0_core::parser::response::Response::{Reject, Success};
2727
use celma_v0_core::parser::specs::Parse;
28-
use celma_v0_core::stream::char_stream::CharStream;
28+
use celma_v0_core::stream::array_stream::ArrayStream;
2929
use celma_v0_core::stream::position::Position;
3030
use celma_v0_core::stream::specs::Stream;
3131
use celma_v0_macro::parsec_rules;
@@ -59,7 +59,7 @@ fn mk_f64(a: Vec<char>) -> f64 {
5959
}
6060

6161
parsec_rules!(
62-
let json:{JSON} = S _=(array | object | string | null | boolean | number) S
62+
let json:{JSON} = S _=(string | number | boolean | null | array | object ) S
6363
let number:{JSON} = f=NUMBER -> {JSON::Number(f)}
6464
let string:{JSON} = s=STRING -> {JSON::String(s)}
6565
let null:{JSON} = "null" -> {JSON::Null}
@@ -82,46 +82,58 @@ parsec_rules!(
8282
// -------------------------------------------------------------------------------------------------
8383

8484
fn json_data(b: &mut Bencher) {
85-
let data = include_str!("data/data.json");
85+
let vec = include_str!("data/data.json")
86+
.chars()
87+
.collect::<Vec<char>>();
88+
let data = vec.as_slice();
8689
b.bytes = data.len() as u64;
8790
parse(b, data)
8891
}
8992

9093
// -------------------------------------------------------------------------------------------------
9194

9295
fn json_canada_pest(b: &mut Bencher) {
93-
let data = include_str!("data/canada_pest.json");
96+
let vec = include_str!("data/canada_pest.json")
97+
.chars()
98+
.collect::<Vec<char>>();
99+
let data = vec.as_slice();
94100
b.bytes = data.len() as u64;
95101
parse(b, data)
96102
}
97103

98104
// -------------------------------------------------------------------------------------------------
99105

100106
fn json_canada_nom(b: &mut Bencher) {
101-
let data = include_str!("data/canada_nom.json");
107+
let vec = include_str!("data/canada_nom.json")
108+
.chars()
109+
.collect::<Vec<char>>();
110+
let data = vec.as_slice();
102111
b.bytes = data.len() as u64;
103112
parse(b, data)
104113
}
105114

106115
// -------------------------------------------------------------------------------------------------
107116

108117
fn json_apache(b: &mut Bencher) {
109-
let data = include_str!("data/apache_builds.json");
118+
let vec = include_str!("data/apache_builds.json")
119+
.chars()
120+
.collect::<Vec<char>>();
121+
let data = vec.as_slice();
110122
b.bytes = data.len() as u64;
111123
parse(b, data)
112124
}
113125

114126
// -------------------------------------------------------------------------------------------------
115127

116-
fn parse(b: &mut Bencher, buffer: &str) {
117-
let stream = CharStream::new_with_position(buffer, <usize>::new());
128+
fn parse(b: &mut Bencher, buffer: &[char]) {
129+
let stream = ArrayStream::new_with_position(buffer, <usize>::new());
118130

119131
b.iter(|| {
120132
let response = json().and_left(eos()).parse(black_box(stream.clone()));
121133

122134
match response {
123135
Success(_, _, _) => (),
124-
Reject(s, _) => panic!("parse error at {:?}", s.position()),
136+
Reject(s, _) => panic!("parse error for {:?} at {:?}", s.next().0, s.position()),
125137
}
126138
});
127139
}

0 commit comments

Comments
 (0)