Last Updated: February 25, 2016
·
935
· artemeff

Performance of code highlighters

I've testing code highlighters for my project:

  • CodeRay
  • Ultraviolet
  • Highlight

On:

Intel Core i5 @ 3Ghz
16Gb RAM
SSD OCZ VERTEX 3  

Results:

For single parsing:
       user     system      total        real
CR:  0.010000   0.000000   0.010000 (  0.017303)
Uv:  0.060000   0.000000   0.060000 (  0.063898)
Hl:  0.000000   0.000000   0.330000 (  0.341409)

For 1000:
       user     system      total        real
CR:  1.440000   0.000000   1.440000 (  1.452495)
Uv: 18.750000   0.110000  18.860000 ( 18.855356)
Hl:  0.220000   0.580000 341.890000 (343.663456)

Benchmark code:

# gems
require "rubygems"
require "benchmark"
require "coderay"
require "Uv"
require "simplabs/highlight"

cr, uv, hl = ""

code = <<CODE
class Test

  attr_accessor :test

  def initialize test
    @test = test
  end

  def print
    puts "print: #{@test}"
  end

  def another_method with, params
    params.each do |p|
      with << p.to_s
    end
  end
end

CODE

puts "For single parsing:"

Benchmark.bm do |x|
  # CodeRay
  x.report ("CR:") { cr = CodeRay.scan(code, :ruby).html }
  # Ultraviolet
  x.report ("Uv:") { uv = Uv.parse code, "xhtml", "ruby", true, "amy" }
  # Highlight
  x.report ("Hl:") { hl = Simplabs::Highlight.highlight :ruby, code }
end

puts "For 1000:"

Benchmark.bm do |x|
  # CodeRay
  x.report ("CR:") { for i in (1..1_000); CodeRay.scan(code, :ruby).html; end }
  # Ultraviolet
  x.report ("Uv:") { for i in (1..1_000); Uv.parse code, "xhtml", "ruby", true, "amy"; end }
  # Highlight
  x.report ("Hl:") { for i in (1..1_000); Simplabs::Highlight.highlight :ruby, code; end }
end

puts "CodeRay:\n\n#{cr}\n\n\nUltraviolet:\n\n#{uv}\n\n\nHighlight:\n\n#{hl}"