This page will freeze your browser for a while as the benchmark is done on the main thread. This will not be fixed as this is only a testing page and I don't want to spend the time to move the work off-thread, the code was written at 2 in the morning and is rather convoluted.

The "original" test iterates over the word list and uses the .includes() function to check if the string being tested contains the word. This appears to be faster in firefox based browsers (as of firefox 70.0.1).

The "new" tests first generate a tree (the time it takes to do this is listed as "list generation time" below) where each node is an array of length 27, entries 0-25 represent the 26 letters of the alphabet and are ether undefined or contain the next nodes in the array.The 26th entry is the number of words formed by the sequence of letters used to reach that node. The 27th entry is ether empty or a Boolean (always true) which denotes the end of a word (this is only used while generating the array).
When the tests are run they iterate over each character of the string being tested and (beginning at the top) traverse the array using each subsequent character as the key in the next node down. This continues until it hits a node where the next layer down is undefined at which point it adds the value of current_node[26] to the score and moves on to the next letter.

The difference between "recursive" and "loop" is how they traverse the tree. The recursive version uses a function that calls itself and the loop version uses a while loop. Both appear evenly matched in chrome based browsers (read: all non-firefox browsers) (as of 78.0) although "recursive" seems to have a slight edge.

The values provided for each test are:

  1. Time taken: the time taken to test the poem 'The Raven' 5 times as measured by performance.now() in ms.
  2. Result (en): the score of the poem 'The Raven' as calculated by the test.
  3. Result (rot13): the score of the rot13 of the poem 'The Raven' as calculated by the test. This should be less than Result(en).
original: time taken: result (en): result (rot13):
new (recursive): time taken: result (en): result (rot13):
new (loop): time taken: result (en): result (rot13):
list generation time:

this site's home page