tmikov / linebench

Benchmarks for reading a text file line by line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

README

linebench

A collection of simple benchmarks for reading a text file line by line and printing it. The techniques used are supposed to be easy for each corresponding language/ environment. The results are surprising.

  • C++ iostreams and std::getline()

  • stdio gets/puts

  • GNU readline

  • A scanner generated by FLEX

  • Python

Building

It has only been tested under MacOSX but it is expected it will work without any modification under Linux. Windows is not supported, though it could probably work under Cygwin. Contributions improving portability are welcome.

It requires CMake v2.8 or later. To build, in the source directory:

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make

Then to run, from within the build directory we just created:

../run-bench.sh .. sample-input.txt

Results

On a test machine:

Method

time

factor

C gets

0.590s

1x

C++ iostreams

0.295s

0.51x

FLEX scanner

0.782s

1.33x

C GNU readline

0.474s

0.80x

Python

1.985s

3.3x

NodeJS

1.089s

1.86x

About

Benchmarks for reading a text file line by line

License:The Unlicense


Languages

Language:CMake 29.2%Language:Shell 28.2%Language:C++ 20.9%Language:C 10.5%Language:Python 8.0%Language:JavaScript 3.2%