loccount counts source lines of code (ignoring blank lines and comments) for many, many languages. It’s also very effective at identifying obscure and historical languages, providing a basic description and links on request.
Note: The default reporting format is meant for human eyes and is not guaranteed to be stable over releases as more features are added. If you want a stable format for an analysis pipeline, use the JSON output.
loccount started out as a re-implementation in Go of David A. Wheeler’s sloccount tool, but has since grown a lot more capability. It is faster, handles more different languages, can report LLOC as well as SLOC, and can do COCOMO II as well as COCOMO I estimates. Because it’s one source file in Go, it is easier to maintain and extend than the multi-file, multi-language implementation of the original.
The -t option also makes it useful for identifying the origin of alien source files; using a Go regular expression against language names and aliases, you can usually get a brief description of any language that appears in a loccount report. By default that report is plain text; add -H to emit HTML instead.
Use --no-duplicates to count files with identical contents only once across all input paths. By default, all copies are counted.
You can view a webified version of the language database at here.
Comparisons
Why use this counter rather than competitors like tokei, scc, or gocloc?
-
loccount has very, very broad coverage of programming languages, document markups. Here’s a comparison:
Languages Counters Repository 958
loccount
453
pygments
377
scc
361
cloc
331
tokei
187
gocloc
149
polyglot
120
loc
118
ohcount
76
sloc
30
ocloc
27
sloccount
The Pygments figure counts normalized lexer names after excluding the listed mixed-language template combinations, session transcripts, logs, tracebacks, and test-run output.
-
loccount reports LLOC as well as SLOC when possible.
-
loccount can do COCOMO II cost estimation.
-
loccount can report in self-describing JSON for postprocessing.
-
loccount can usually tell you what an unidentified source file is.
-
loccount is very fast, exploiting as many processors as you have.
Build instructions
To build it, have the Go compiler and Python 3.10+ installed and do "make" in the top-level directory.
If you get a message about genericLanguages being undefined, you did "go build" which is not enough. The make production generates some Go from a JSON file; this is why you needed Python installed.
You can run a self-test with 'make check'. The sample sources are in the test/ subdirectory.
See hacking.adoc for information on how to add support for a language. You may also want to read the design notes in design-notes.adoc
Packages
This code is commonly packaged as "loccount".