danmar / simplecpp

C++ preprocessor
BSD Zero Clause License
209 stars 83 forks source link

optimized `lastLine()` usage in `readfile()` #325

Closed firewave closed 1 year ago

firewave commented 1 year ago

Using the headers from https://sourceforge.net/p/cppcheck/discussion/development/thread/4e3ff7c875/:

a.h

Benchmark 1: ./simplecpp -q test.c
  Time (mean ± σ):       9.2 ms ±   0.6 ms    [User: 8.1 ms, System: 1.2 ms]
  Range (min … max):     8.3 ms …  11.4 ms    250 runs
Benchmark 1: ./simplecpp -q test.c
  Time (mean ± σ):       3.4 ms ±   0.5 ms    [User: 2.6 ms, System: 1.2 ms]
  Range (min … max):     2.3 ms …   5.8 ms    488 runs

b.h

Benchmark 1: ./simplecpp -q test.c
  Time (mean ± σ):     140.6 ms ±   1.7 ms    [User: 137.2 ms, System: 3.3 ms]
  Range (min … max):   137.6 ms … 143.8 ms    20 runs
Benchmark 1: ./simplecpp -q test.c
  Time (mean ± σ):      13.2 ms ±   1.4 ms    [User: 10.4 ms, System: 2.8 ms]
  Range (min … max):    11.7 ms …  19.3 ms    148 runs
firewave commented 1 year ago

The remaining lastLine() can also be removed but that gets rather messy.

firewave commented 1 year ago

@danmar anything still to do here?