loccount started out as a re-implementation of David A. Wheeler’s sloccount tool in Go, 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 algorithms are largely unchanged and can be expected to produce identical numbers for languages supported by both tools. Python is an exception; loccount corrects buggy counting of single-quote multi-line literals in sloccount 2.26.

The -t option also makes it useful for identifying the origin of alien source files; using it, you can usually get a brief description of any language that appears in a loccount report.

Why use this counter rather than competitors like tokei, scc, or gocloc?

  1. loccount has very, very broad coverage of programming languages, document markups, and configuration formats; over 400 different kinds.

  2. loccount reports LLOC as well as SLOC when possible.

  3. loccount can do COCOMO II cost estimation.

  4. loccount can report in self-describing JSON for postprocessing.

  5. loccount can usually tell you what an unidentified source file is.

  6. loccount is very fast, exploiting as many processors as you have.

To build it, have the Go compiler and Python 3 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

This code is commonly packaged as "loccount".

Repology package status