Skip to content

Instantly share code, notes, and snippets.

@jdkato
Created September 3, 2016 22:18
Show Gist options
  • Save jdkato/53b7e12c2dec682962564bc1e85707a2 to your computer and use it in GitHub Desktop.
Save jdkato/53b7e12c2dec682962564bc1e85707a2 to your computer and use it in GitHub Desktop.
import time
import os
from cypher import identify
from dev import LANG_INFO
supported = [s.lower() for s in LANG_INFO.keys()]
data = '' # path to benchmark data (https://github.com/nbraud/benchmarksgame/tree/master/bench)
name2ext = {
'csharp': 'C#', 'gcc': 'C', 'gpp': 'C++', 'ghc': 'Haskell',
'jruby': 'Ruby', 'python3': 'Python', 'hack': 'PHP', 'yarv': 'Ruby',
'C-sharp': 'C#'
}
count = 0.0
correct = 0
before = time.time()
for subdir, _, files in os.walk(data):
for f in files:
path = os.path.join(subdir, f)
ext = path.split(".")[-1]
if ext in name2ext:
ext = name2ext.get(ext).lower()
if ext in supported:
count += 1
guess = identify(path).lower()
if guess == ext:
correct += 1
else:
print(guess, path)
print("{} ({} / {})".format(round(correct / count, 3), correct, count))
print("Time: {}".format(time.time() - before))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment