lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Aug 3, 2008 at 8:38 PM, Petite Abeille <petite_abeille@mac.com> wrote:
> Cool. Have you benchmarked/tested that against Niklas Frykholm markdown.lua?
>
> http://www.frykholm.se/files/markdown.lua
>
> How does the two implementations compare?

I did a quick test to get an idea of how they compare after I wrote
this, and I've just done another test. Discount is far faster than any
other Markdown implementation. I tested by parsing the entire Markdown
test suite (consisting of 22 tests) 100 times,
<http://daringfireball.net/projects/downloads/MarkdownTest_1.0.3.tbz>.

$ cat bench.lua
require('markdown')
discount = require('discount')

local function read_file(fn)
  local file = assert(io.open(fn))
  local contents = assert(file:read('*a'))
  file:close()
  return contents
end

text = {}

for fn in io.popen('find Tests -type f -name "*.text"'):lines() do
  text[fn] = read_file(fn)
end

function test_implementation(mkd, name, rep)
  rep = rep or 100
  print("Testing "..name)
  local start_time = os.clock()
  for i=1, rep do
    for fn, contents in pairs(text) do
      mkd(contents)
    end
  end
  local end_time = os.clock()
  print("Time: "..(end_time-start_time))
end

test_implementation(discount, "lua-discount")
print('')
test_implementation(markdown, "Markdown.lua")

 $ lua bench.lua
Testing lua-discount
Time: 0.32

Testing Markdown.lua
Time: 61.61

This test was performed on lua-discount compiled with -O2.
Unfortunately, luarocks currently does not specify any level of
optimization in the default CFLAGS on Unix. lua-discount takes 0.59
seconds using this unoptimized build.

This makes markdown.lua look bad, but I'm not sure if it's
particularly slow compared to other language implementations (the
original Markdown.pl is hardly known as a speed daemon). The advantage
of markdown.lua is it doesn't depend on a C library, and it's portable
wherever Lua is. markdown.lua is probably easily fast enough for
lua-discount is clearly significantly faster, but this comes at the
price of portability and ease of installation. You could easily try to
require lua-discount and fall back to markdown.lua if it is not
available - if you pass the 'nopants' options to the discount
function, the output should be very similar. Discount passes the
markdown test suite, I do not know if markdown.lua has been tested
against it.

Discount also has several extensions to the Markdown syntax which you
can read about on the Discount homepage. lua-discount is not built
with support for pandoc document headers, but I did intend to build
with support for the definition list extension (forgot the #define in
the current release, added it to config.h in the git repository). You
may also find the options to the discount function offer useful extra
functionality, which are documented in my original email.

I hope this goes some way to answer your questions.

Regards,

Alex