Created
September 3, 2016 22:18
-
-
Save jdkato/53b7e12c2dec682962564bc1e85707a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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