Created
October 22, 2012 18:23
-
-
Save chase/3933165 to your computer and use it in GitHub Desktop.
Times for highlightAuto Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function highlightAuto(text) { | |
var result = { | |
keyword_count: 0, | |
relevance: 0, | |
value: escape(text) | |
}; | |
var second_best = result; | |
for (var key in languages) { | |
console.time(key); // Start timer | |
if (!languages.hasOwnProperty(key)) | |
continue; | |
var current = highlight(key, text); | |
current.language = key; | |
if (current.keyword_count + current.relevance > second_best.keyword_count + second_best.relevance) { | |
second_best = current; | |
} | |
if (current.keyword_count + current.relevance > result.keyword_count + result.relevance) { | |
second_best = result; | |
result = current; | |
} | |
console.timeEnd(key); // End timer | |
} | |
if (second_best.language) { | |
result.second_best = second_best; | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using: | |
node -e "require('highlight.js').highlightAuto('echo $content | docpad render sampleFileNameWithExtensions\n')" | |
bash: 2ms | |
erlang: 5ms | |
cs: 2ms | |
brainfuck: 0ms | |
ruby: 4ms | |
rust: 2ms | |
rib: 0ms | |
diff: 0ms | |
javascript: 2ms | |
glsl: 0ms | |
rsl: 1ms | |
lua: 1ms | |
xml: 4ms | |
markdown: 1ms | |
css: 2ms | |
lisp: 2ms | |
profile: 1ms | |
http: 1ms | |
java: 1ms | |
php: 2ms | |
haskell: 1ms | |
1c: 2ms | |
python: 1ms | |
smalltalk: 268601ms | |
tex: 1ms | |
actionscript: 1ms | |
sql: 4ms | |
vala: 1ms | |
ini: 1ms | |
d: 2ms | |
axapta: 0ms | |
perl: 7ms | |
scala: 1ms | |
cmake: 0ms | |
objectivec: 0ms | |
avrasm: 1ms | |
vhdl: 1ms | |
coffeescript: 3ms | |
nginx: 2ms | |
erlang-repl: 2ms | |
r: 1ms | |
json: 1ms | |
django: 7ms | |
delphi: 1ms | |
vbscript: 0ms | |
mel: 1ms | |
dos: 0ms | |
apache: 1ms | |
applescript: 1ms | |
cpp: 1ms | |
matlab: 0ms | |
parser3: 1ms | |
clojure: 1ms | |
go: 3ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment