pygments / pygments.rb

💎 Ruby wrapper for Pygments syntax highlighter
MIT License
572 stars 141 forks source link

Use PyPy if available #136

Closed aroben closed 9 years ago

aroben commented 10 years ago

It's slower to launch than CPython, but around 30% faster once running.

CPython:

$ bundle exec ruby bench.rb
Benchmarking....
Size: 15523 bytes
Iterations: 10
                                               user     system      total        real
pygments popen                               0.010000   0.010000   0.020000 (  0.555983)
pygments popen (process already started)     0.000000   0.000000   0.000000 (  0.241948)
pygments popen (process already started 2)   0.010000   0.000000   0.010000 (  0.232061)

$ bundle exec ruby bench.rb 20 25
Benchmarking....
Size: 388075 bytes
Iterations: 20
                                               user     system      total        real
pygments popen                               0.080000   0.040000   0.130000 ( 11.803712)
pygments popen (process already started)     0.090000   0.040000   0.130000 ( 11.600885)
pygments popen (process already started 2)   0.090000   0.040000   0.130000 ( 11.567272)

PyPy:

$ bundle exec ruby bench.rb
Benchmarking....
Size: 15523 bytes
Iterations: 10
                                               user     system      total        real
pygments popen                               0.010000   0.000000   0.020000 (  0.997430)
pygments popen (process already started)     0.010000   0.000000   0.010000 (  0.366487)
pygments popen (process already started 2)   0.000000   0.010000   0.010000 (  0.273575)

$ bundle exec ruby bench.rb 20 25
Benchmarking....
Size: 388075 bytes
Iterations: 20
                                               user     system      total        real
pygments popen                               0.080000   0.030000   0.110000 (  9.264323)
pygments popen (process already started)     0.080000   0.040000   0.120000 (  7.407072)
pygments popen (process already started 2)   0.080000   0.030000   0.110000 (  7.446369)

/cc @tmm1 @tnm

aroben commented 10 years ago

And just to show that the speedup isn't only on large files:

CPython:

$ bundle exec ruby bench.rb 500
Benchmarking....
Size: 15523 bytes
Iterations: 500
                                               user     system      total        real
pygments popen                               0.300000   0.120000   0.420000 ( 12.263667)
pygments popen (process already started)     0.280000   0.120000   0.400000 ( 12.045258)
pygments popen (process already started 2)   0.280000   0.120000   0.400000 ( 11.901942)

PyPy:

$ bundle exec ruby bench.rb 500
Benchmarking....
Size: 15523 bytes
Iterations: 500
                                               user     system      total        real
pygments popen                               0.310000   0.130000   0.440000 ( 10.554289)
pygments popen (process already started)     0.300000   0.130000   0.430000 (  8.539325)
pygments popen (process already started 2)   0.310000   0.120000   0.430000 (  8.608728)
aroben commented 9 years ago

PyPy has a slower startup time than CPython, so this probably isn't an appropriate default. It would still be nice to support as an option though.