Duplicate Detection in CodeRush versus Code Clone Analysis in Visual Studio 2011
CodeRush Duplicate Code Detection (DDC) analysis runs in the background while you work in the Visual Studio IDE. Visual Studio 2011 Developer Preview has a similar feature called Code Clone Analysis (CCA). Both features find code duplications, so it is possible to undertake a brief overview of each feature and compare them. Please note that this article was written using the Visual Studio 11 Developer Preview, and as such, certain functionality may be subject to change before the final release. The version of the IDE Tools/CodeRush used for comparison is 11.2, which is certainly subject to change.
UI & Integration
CodeRush DDC highlights code duplicates right inside the code editor:
It also has a special Duplicate Code tool window that allows you to review all code duplicates:
Visual Studio Code Clone Analysis does not highlight duplicates inside the code editor, but it has a tool window to review all code duplicates:
Analysis speed
Measurements were taken on one of the open source projects that contains 86 projects, and its overall size is 70M bytes.
First analysis run:
Time |
|
VS Code Clone Analysis | 19 min 15 sec |
CR DDC inside VS (default analysis level = 4) | 2 min 45 sec |
CR DDC inside VS (analysis level = 1) | 4 min 32 sec |
Second analysis run (after VS is reloaded):
Time |
|
VS Code Clone Analysis | 19 min 0 sec |
CR DDC inside VS (default analysis level = 4) | 0 min 15 sec |
CR DDC inside VS (analysis level = 1) | 3 min 37 sec |
As you can see, there’s some difference in the speed of analysis, especially in the second and subsequent analysis runs.
Capabilities
Both features do the same thing – they analyze your code to find code duplicates. Let’s see what capabilities both provide:
Visual Studio CCA |
CodeRush DDC |
|
Configurable Analysis level | No: always shows matches categorized into Exact/Strong/Medium/Week categories | Yes, the analysis level can be set from 0 to 10th level |
Entire solution analysis | Yes* | Yes |
Find Matching Clones | Yes | No** |
Analysis exclusions | For specific files*** | For projects, folders, and files via two mouse clicks |
Consolidation | No | Yes |
* code clones less than 10 statements long won’t be discovered when analyzing the entire solution
** planned for the future release
*** files can be excluded by creating a file in the project with a “.codeclonesettings” extension and then adding some XML data to the created file to exclude the appropriate files in the project.
Consolidation
Because the primary purpose of duplicate code detection is removing code duplications from the system, it is very important and useful to have a feature that does this automatically for you. CodeRush DDC has a Code Consolidation engine that removes code duplications by replacing them with a functionally identical single block of code. Other existing duplicate code analysis tools does not have such a capability at the moment.
The consolidation preview hint allows you to review the changes being made:
Want to learn more?
- Duplicate Detection and Consolidation Overview
- Duplicate Real-time detection in Visual Studio
- Duplicate Detection Visual Studio tool window
- Duplicate Detection Using the Stand-alone Application
- Duplicate Consolidation inside Visual Studio
- Duplicate Detection analysis options