[OT] LOC counting tool

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

flok

Re: v1.5

Post by flok »

When can we expect a source release?
cetormenter
Posts: 170
Joined: Sun Oct 28, 2012 9:46 pm

Re: v1.5

Post by cetormenter »

Current dev version of Nirvana

Code: Select all

-------------------------------------------------------------------------------
Type                      Files       Blank     Comment Punctuation        Code
-------------------------------------------------------------------------------
C++ source                    1         847         851         766       2'728
C/C++ header                  1          91           4          55         475
-------------------------------------------------------------------------------
Total                         2         938         855         821       3'203
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: v1.5

Post by cdani »

cetormenter wrote:Current dev version of Nirvana

Code: Select all

-------------------------------------------------------------------------------
Type                      Files       Blank     Comment Punctuation        Code
-------------------------------------------------------------------------------
C++ source                    1         847         851         766       2'728
C/C++ header                  1          91           4          55         475
-------------------------------------------------------------------------------
Total                         2         938         855         821       3'203
Nice! Do you compress the code a lot or is pretty simple? Either case is clear that you have optimized it a lot!
mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: v1.5

Post by mar »

mvk wrote:I was already using CountLoc v1.0 to track where Floyd was going.

Before:

Code: Select all

CountLoc v1.0, (c) 2015 mar
-------------------------------------------------------------------------------
Type                         Files          Blank        Comment           Code
-------------------------------------------------------------------------------
C source                        13            791            939           2810
C/C++ header                     8            195            307            488
-------------------------------------------------------------------------------
Total                           21            986           1246           3298
New CountLoc:

Code: Select all

-------------------------------------------------------------------------------
Type                      Files       Blank     Comment Punctuation        Code
-------------------------------------------------------------------------------
C source                     13         791         939         405       2'810
C/C++ header                  8         195         307          24         488
-------------------------------------------------------------------------------
Total                        21         986       1'246         429       3'298
1. No version is actually listed
2. Is there a way to hide those thousands ticks? (Or maybe much better: to give machine readable output as an option, such as JSON, CSV or whatever).
3. Good: the categories indeed add up again to the raw line count. (v1.0 made lines disappear). It is now more informative than cloc for me:

Reference (cloc):

Code: Select all

http://cloc.sourceforge.net v 1.64  T=0.10 s (209.5 files/s, 59454.4 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
C                               13            791            939           3215
C/C++ Header                     8            195            307            512
-------------------------------------------------------------------------------
SUM:                            21            986           1246           3727
-------------------------------------------------------------------------------
Nice to see it's useful :)

Ad 1) I decided to remove version info as I considered it useless. Version is shown if you run CountLoc without arguments.
Ad 2) You can disable pretty-printing with -np argument.
Machine readable output is a good idea and should be no problem, I will think about it. Probably CSV as it should be easier to parse than JSON.
Ad 3) You can use -g argument to count punctuation as code (punctuation column will disappear)
mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: v1.5

Post by mar »

flok wrote:When can we expect a source release?
Good question.
It's currently built on top of my framework (86k lines and still far from finished) that can do way more than what's necessary for CountLoc.
I also use my own strings, collections, streams, directory enumerators, inflate and zip parser and so on so it has no dependecies on external projects.
This is ideal for me but I'd probably have to rewrite some parts using STL to minimize amount of code
(needless to say I don't consider myself an expert when it comes to STL :)

So I'd have to dismantle it into a bare minimum needed by CountLoc first.
I thought about rewriting it in C but that would require substantial effort and time so I won't do this.
Also some parts of the code could use refactoring/face lifting before going open source as it got a bit ugly when I added support for additional languages -
going open source implies responsibility for the quality of what you release (I didn't understand this in the past :)
Plus you have to attach a license.
I'd then have to maintain an additional project that would cost time.

So right now, I'm not sure as it would cost me a non-trivial amount of effort.
Should there be enough interest I might do that though.
mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

v1.6 (csv)

Post by mar »

mvk wrote:1. No version is actually listed
2. Is there a way to hide those thousands ticks? (Or maybe much better: to give machine readable output as an option, such as JSON, CSV or whatever).
I've just uploaded a new version that addresses both problems.
Link is the same, i.e. http://www.crabaware.com/Utils/CountLoc/CountLoc.zip
You can now use -v argument to always display version.
By using -csv <filename>, CountLoc will output to a csv file for easier machine processing.
You can also use -csv stdout and the csv will be printed to stdout instead;
this can be used to redirect stdout or chain commands using pipes etc.
cetormenter
Posts: 170
Joined: Sun Oct 28, 2012 9:46 pm

Re: v1.5

Post by cetormenter »

cdani wrote:
cetormenter wrote:Current dev version of Nirvana

Code: Select all

-------------------------------------------------------------------------------
Type                      Files       Blank     Comment Punctuation        Code
-------------------------------------------------------------------------------
C++ source                    1         847         851         766       2'728
C/C++ header                  1          91           4          55         475
-------------------------------------------------------------------------------
Total                         2         938         855         821       3'203
Nice! Do you compress the code a lot or is pretty simple? Either case is clear that you have optimized it a lot!
I am not sure. I was surprised at the result as well. Visual Studio says there are ~7,000 lines of code. Obviously this is very different from the eloc.

I would say Nirvana is pretty simple though. Every time I try to add more evaluation terms or search parameters they seem to fail. My time is now pretty much spent trying to add new terms, having them fail, and then I quickly run out of new ideas to try. I then just put my code into a huge tuning session and hope better default values fall out.
mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: v1.5

Post by mar »

cetormenter wrote:I am not sure. I was surprised at the result as well. Visual Studio says there are ~7,000 lines of code. Obviously this is very different from the eloc.

That's interesting.
Summing blank + comment + punctuation + code totals should give physical line count.
I tried this with Floyd and I got the same summed result as with

Code: Select all

cat *.c *.h | wc -l
Assuming VS counts physical lines, I get ~6k for what you posted, not 7k so I wonder why.
There are only two possibilities: either I have a bug in my program or not everything was counted.
mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

v1.7

Post by mar »

I think I'm done with the tool (and spamming :)
Download link: http://www.crabaware.com/Utils/CountLoc/CountLoc.zip

new features:
- optionally show progress
- experimental support for tar/tar.gz
- diff against previous csv snapshot (can go negative as well)
- optionally scan archives
- stdin (useful to pipe with xz for example)
- force extension (for example parse inc as pas)
- slightly faster processing (say 3%?)
Dann Corbit
Posts: 12541
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: v1.7

Post by Dann Corbit »

Interesting. It turns out that Gull and Stockfish are pretty close to the same size.

Code: Select all

f&#58;\project\dcorbit\Gull 3>countloc .
-------------------------------------------------------------------------------
Type                      Files       Blank     Comment Punctuation        Code
-------------------------------------------------------------------------------
C++ source                    1         381          40         794       6'051
Python source                 4          33          14           0         146
-------------------------------------------------------------------------------
Total                         5         414          54         794       6'197

f&#58;\project\dcorbit\Gull 3>countloc "\project\dcorbit\Stockfish-master"
-------------------------------------------------------------------------------
Type                      Files       Blank     Comment Punctuation        Code
-------------------------------------------------------------------------------
C++ source                   26       2'203       1'533       1'113       5'881
C/C++ header                 25         683         609         281       1'623
-------------------------------------------------------------------------------
Total                        51       2'886       2'142       1'394       7'504