terryyin / lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
Other
1.85k stars 250 forks source link

Remove warnings from output if no thresholds exceeded #151

Closed mdmedley closed 8 years ago

mdmedley commented 8 years ago

The very first time I ran the analyzer I was confused because I saw this big "!!!! Warnings" section with nothing under it. So I removed it. Then I realized that knowing what the thresholds were in your execution is important so I wrote a new print method to give the user that information is a less alarming message. Plus a couple other minor changes to the README.rst and the setup.py files.

Example Output

================================================
  NLOC    CCN   token  PARAM  length  location  
------------------------------------------------
1 file analyzed.
==============================================================
NLOC    Avg.NLOC  AvgCCN  Avg.token  function_cnt    file
--------------------------------------------------------------
     13       0.0     0.0        0.0         0     profile.py

=============================================================================================
No thresholds exceeded (cyclomatic_complexity > 15 or length > 1000 or parameter_count > 100)
==========================================================================================
Total nloc   Avg.NLOC  AvgCCN  Avg.token   Fun Cnt  Warning cnt   Fun Rt   nloc Rt
------------------------------------------------------------------------------------------
        13       0.0     0.0        0.0        1            0      0.00    0.00
mdmedley commented 8 years ago

@rakhimov @terryyin I modified my pull request to remove the duplicate call which prevents the need to exhaust the generator just recreate it, thus speeding up the application in the cases where there are warnings.

mdmedley commented 8 years ago

I also seem to have broken the build. @terryyin or @rakhimov if either of you know exactly where to fix this it would greatly reduce the time it's going to take me to figure it out.

rakhimov commented 8 years ago

Testing on Linux kernel code (quad-core i7 laptop):

lizard -t 6 -Ecpre -a 6 -l cpp > complexity.txt

current master branch:

real    4m12.183s
user    25m3.672s
sys 0m5.340s

Not bad for 12 million lines of code with 21,116 warnings. The output file weighs 48M.

with @mdmedley patch

real     4m9.342s
user 24m45.100s
sys 0m7.672s

There seems to be some speedup, maybe? P.S. It is frying my laptop: 80-86 *C :-)

rakhimov commented 8 years ago

The same benchmark as before with pypy:

>  time pypy ~/projects/lizard/lizard.py -t 6 -Ecpre -a 6 -l cpp > complexity-pypy.txt 

real    1m30.777s
user    9m0.064s
sys 0m7.012s

Almost 3x speedup. Moreover, it doesn't fry my laptop: 67-70 *C.

rakhimov commented 8 years ago

As you can notice from the timings, multi-threading is scaling pretty well.

mdmedley commented 8 years ago

Test test_exit_with_non_zero_when_more_warning_than_ignored_number is passing on my local branch...

nosetests test
...............................................................................................................SS................................................................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 497 tests in 0.376s

OK (SKIP=2)

But I do see that I only have 497 tests while the Travis output has 501 tests.

rakhimov commented 8 years ago

tests are passing. the problem is that for-else wart.

mdmedley commented 8 years ago

@rakhimov what do you mean by that I don't understand

rakhimov commented 8 years ago

There's a good old idiom in C++ to do what for-else is trying to address: http://llvm.org/docs/CodingStandards.html#turn-predicate-loops-into-predicate-functions

terryyin commented 8 years ago

Thanks for the work and extra clean up:-)