rubik / radon

Various code metrics for Python code
http://radon.readthedocs.org/
MIT License
1.75k stars 118 forks source link

takes 2.5 hours to run (other tools take take less than 5 min) #97

Closed grayaii closed 8 years ago

grayaii commented 8 years ago

I've been trying various tools to get CC of my project and I found that running radon takes around 2.5 hours to run through my project, whereas other tools like mccabe and lizard take around 5 min to run:

echo "getting mccabe..."
find my_repo -name "*.py" -exec python -m mccabe {} \; > mccabe.txt
echo "getting lizard..."
lizard my_repo -l "python" -s "cyclomatic_complexity" > lizard.txt
echo "getting radon raw..."
radon raw my_repo -s > raw.txt
echo "getting radon cc..."
radon cc my_repo -s --total-average > cc.txt

I'm just curious if there is an underlying issue in performance or if you know a way to speed up the execution. thanks for writing this tool.

rubik commented 8 years ago

The problem is that you are not comparing the same thing. The other tools only compute cyclomatic complexity, so you should compare them with radon cc only.

To compute cyclomatic complexity Radon makes use of the Python AST parser, which is written in C and therefore it should be quite fast. On the other hand, to compute raw metrics Radon needs the source code tokens. It uses the tokenize module from the standard library, which is written in Python and really slow compared to AST parsing. I'm willing to bet that the majority of those 2.5 hours are spent in radon raw. Let me know.

grayaii commented 8 years ago

you're right! the cc command is lightning fast, but the raw command is super slow.

rubik commented 8 years ago

Yeah. Unfortunately there's no simple way to work around the slowness of the tokenize module.