Skip to content

Commit

Permalink
🔧 make cpp benchmark use range based for
Browse files Browse the repository at this point in the history
  • Loading branch information
AriaFallah committed May 29, 2017
1 parent aae1759 commit 2fa91ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 5 additions & 3 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Benchmark

#### My parser (C++)
Parses `sample.csv`, and outputs the number of rows.

#### My parser (c++)
Compiled with `clang++ -std=c++11 -O2`
```
$ time ./bench.out sample.csv
36634
0.06 real 0.06 user 0.00 sys
0.04 real 0.04 user 0.00 sys
```

#### rust-csv (rust)
Expand All @@ -16,7 +18,7 @@ $ time ./rust/target/release/bench sample.csv
0.02 real 0.01 user 0.00 sys
```

#### csv-parser (Node.js)
#### csv-parser (node.js)
```
$ time node js/main.js sample.csv
36634
Expand Down
10 changes: 2 additions & 8 deletions benchmark/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ int main(int, char **argv) {
std::ifstream f(argv[1]);
CsvParser parser(f);

while (true) {
auto field = parser.next_field();
if (field.type == FieldType::ROW_END) {
++count;
}
if (field.type == FieldType::CSV_END) {
break;
}
for (auto& row : parser) {
++count;
}

std::cout << count << std::endl;
Expand Down

0 comments on commit 2fa91ce

Please sign in to comment.