I'm trying to compare source code from multiple github projects, and in particular I'm looking for projects that include large chunks of code from other repositories, or large chunks with small modifications (e.g., variable or function name changes, or changes of a constant from one value to another).

Are there any distance metrics that are particularly suited to source code analysis?


You can check the two links below:

A comparison of code similarity analysers

Measuring Code Similarity in Large-scaled Code Corpora

At the third link below a similarity measure is proposed, which takes into account the amount of the shared information between two sequences. This metric is based on Kolmogorov complexity and it has been applied in measuring the amount of shared information between two computer programs, to enable plagiarism detection.

Shared Information and Program Plagiarism Detection


An Approach to Source-Code Plagiarism Detection and Investigation Using Latent Semantic Analysis reported success in this type of task with the general procedure:

  • Building a term frequency representation of the source code corpus
  • Performing dimensionality reduction using LSA (they found 30 dimensions to be sufficient)
  • Computing cosine similarities of the query documents against corpus documents

Perhaps not much different from what one might do with natural language processing, but they do report reasonably convincing results with this method.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.