我开始思考诸如“80% 的工作由 20% 的代码完成”之类的句子,并想知道是否有任何基础研究、原则或研究可以支持这种说法。
遗憾的是,我的 Google-Fu 不足以给出令人满意的答案。弹出的只是帕累托原理,但我不确定它是否可以应用于这种情况。
关于处理的工作量与 SLOC 的比率是否存在普遍共识?
是否有人对此主题进行过研究,或者是否有统计数据可以支持任何主张?
是否有关于哪种代码属于哪种类别的一般性陈述?(我最初的猜测是80% 的代码 / 20% 的负载部分主要与错误处理有关。)
我开始思考诸如“80% 的工作由 20% 的代码完成”之类的句子,并想知道是否有任何基础研究、原则或研究可以支持这种说法。
遗憾的是,我的 Google-Fu 不足以给出令人满意的答案。弹出的只是帕累托原理,但我不确定它是否可以应用于这种情况。
关于处理的工作量与 SLOC 的比率是否存在普遍共识?
是否有人对此主题进行过研究,或者是否有统计数据可以支持任何主张?
是否有关于哪种代码属于哪种类别的一般性陈述?(我最初的猜测是80% 的代码 / 20% 的负载部分主要与错误处理有关。)
OP 希望查看典型的分析数字。下面是我们的并行程序分析工具 CloneDR 的示例,它可以在大型程序中查找重复代码(在本例中,跨越 77,000 行 COBOL 代码,在 6 个 CPU 的负载率约为 95% 的情况下花费 284 秒的挂钟时间):
C:\DMS\Domains\COBOL\IBMEnterprise\Tools\CloneDR>C:\dms\domains\PARLANSE\Tools\RunTimeSystem\run C:\DMS\Domains\PARLANSE\Tools\RunTimeSystem\StackTraceViewer.P0B CloneDR.std
Loading file C:/DMS/Domains/COBOL/IBMEnterprise/Tools/CloneDR/CloneDR.std
STACK TRACE: CloneDR.p0b
Loading 383 filename references.
Loading 138 foreign function entries.
Loading 107 runtime system entries.
Loading 65,815 stack trace samples.
0.........
100,000..
Read 1567 individual file/lines
Read 129,746 total lines
Removing direct recursion...
Calculating individual counts
Function info count: 490
Missed count: 0
Finished loading file C:/DMS/Domains/COBOL/IBMEnterprise/Tools/CloneDR/CloneDR.std
Lines processed: 129,746
Trace nodes: 490
Recursive nodes: 66,025
Call tree nodes: 129,110
Max call depth: 2,161
Matching isomorphic trees for 490 trace nodes...
Found 46,016 isomorphic trees in 1,158 sets
----------------
* Busiest Isomorphic Trees (cutoff at 1.00%)
----------------
8,274 ( 7,452 | 1) ( 12.6%): GetFirstChild [2661]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
GetFirstChild
5,886 ( 4,859 | 1) ( 8.9%): GetSecondChild [2683]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
GetSecondChild
5,646 ( 505 | 1) ( 8.6%): Lookup [377]:c:/DMS/Domains/PARLANSE/Library/HashTables/Hash.par
Lookup
5,332 ( 4,871 | 1) ( 8.1%): EqualNodes [4653]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
EqualNodes
3,354 ( 2,615 | 1) ( 5.1%): GetNthChildStandard [2516]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
GetNthChildStandard
3,320 ( 3,208 | 1) ( 5.0%): IsListNode [2137]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
IsListNode
2,873 ( 2,723 | 1) ( 4.4%): GetNthChildList [2578]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
GetNthChildList
2,656 ( 22 | 1) ( 4.0%): Subsumes? [1215]:C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
Subsumes?
2,342 ( 998 | 1) ( 3.6%): IsSequenceSpine [254]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ALSTInterface.par
IsSequenceSpine
2,203 ( 706 | 1) ( 3.3%): GetNthChild [1068]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ALSTInterface.par
GetNthChild
2,159 ( 2,077 | 1) ( 3.3%): NumberOfStandardChildren [2347]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
NumberOfStandardChildren
2,017 ( 1,894 | 1) ( 3.1%): GetNodeLiteralType [5904]:c:/DMS/Infrastructure/HyperGraph/Source/Graph.par
GetNodeLiteralType
1,901 ( 1,748 | 2) ( 2.9%): EqualNodes [4653]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
(EqualNodes GetNodeLiteralType)
1,836 ( 1,657 | 1) ( 2.8%): NumberOfChildrenList [2372]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
NumberOfChildrenList
1,041 ( 501 | 1) ( 1.6%): NumberOfChildren [2517]:c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ALSTInterface.par
NumberOfChildren
771 ( 363 | 1) ( 1.2%): FollowSequenceNodePortNthToNode [5369]:c:/DMS/Infrastructure/HyperGraph/Source/Graph.par
FollowSequenceNodePortNthToNode
658 ( 7 | 1) ( 1.0%): AppendNodeToCandidateList [1101]:C:/DMS/Tools/CloneDR/Source/Server/TupleCloneDetector.par
AppendNodeToCandidateList
----------------
* Busiest functions with more than 1.00% of total runtime (excluding children)
----------------
8,274/ 12.6%: (GetFirstChild) Line 2661 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
5,886/ 8.9%: (GetSecondChild) Line 2683 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
5,686/ 8.6%: (Lookup) Line 377 File 331 c:/DMS/Domains/PARLANSE/Library/HashTables/Hash.par
5,588/ 8.5%: (EqualNodes) Line 4653 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
3,354/ 5.1%: (GetNthChildStandard) Line 2516 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
3,335/ 5.1%: (IsListNode) Line 2137 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
2,873/ 4.4%: (GetNthChildList) Line 2578 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
2,656/ 4.0%: (Subsumes?) Line 1215 File 346 C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
2,342/ 3.6%: (IsSequenceSpine) Line 254 File 329 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ALSTInterface.par
2,293/ 3.5%: (GetNthChild) Line 1068 File 329 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ALSTInterface.par
2,159/ 3.3%: (NumberOfStandardChildren) Line 2347 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
2,017/ 3.1%: (GetNodeLiteralType) Line 5904 File 52 c:/DMS/Infrastructure/HyperGraph/Source/Graph.par
1,836/ 2.8%: (NumberOfChildrenList) Line 2372 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
1,108/ 1.7%: (NumberOfChildren) Line 2517 File 329 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ALSTInterface.par
829/ 1.3%: (ComputeSimilaritySubtreePairFast) Line 972 File 337 C:/DMS/Tools/CloneDR/Source/Server/NodeSimilarity.par
771/ 1.2%: (FollowSequenceNodePortNthToNode) Line 5369 File 52 c:/DMS/Infrastructure/HyperGraph/Source/Graph.par
----------------
* Busiest Functions with more than 1.00% of total runtime (including children)
----------------
64,707/ 98.3%: (RTS: Unclassifiable code) Line 1 File 65532
60,105/ 91.3%: (GeneralizeTuple) Line 1323 File 371 C:/DMS/Tools/CloneDR/Source/Server/TupleCloneDetector.par
46,195/ 70.2%: (ComputeSimilaritySelfTrees) Line 1010 File 346 C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
46,192/ 70.2%: (ComputeSimilarityWithProposedAddition) Line 1133 File 346 C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
39,982/ 60.7%: (CD_EqualTrees) Line 198 File 333 C:/DMS/Tools/CloneDR/Source/Server/Misc.par
25,810/ 39.2%: (ComputeSimilaritySelfSequenceElement) Line 824 File 346 C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
25,782/ 39.2%: (ComputeSimilarityTreeVector) Line 384 File 346 C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
20,823/ 31.6%: (ComputeSimilarityTreePairFast) Line 1248 File 337 C:/DMS/Tools/CloneDR/Source/Server/NodeSimilarity.par
17,610/ 26.8%: (ComputeSimilaritySubtreePairFast) Line 972 File 337 C:/DMS/Tools/CloneDR/Source/Server/NodeSimilarity.par
8,274/ 12.6%: (GetFirstChild) Line 2661 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
7,791/ 11.8%: (EqualTreesUseSignatures) Line 577 File 337 C:/DMS/Tools/CloneDR/Source/Server/NodeSimilarity.par
7,634/ 11.6%: (EqualNodes) Line 4653 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
7,543/ 11.5%: (ContainsIdenticalTreeClone) Line 2911 File 346 C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
6,118/ 9.3%: (Lookup) Line 377 File 331 c:/DMS/Domains/PARLANSE/Library/HashTables/Hash.par
5,886/ 8.9%: (GetSecondChild) Line 2683 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
4,345/ 6.6%: (???) Line 2696 File 3 C:/DMS/Tools/CloneDR/Source/Server/CloneDR.par
3,940/ 6.0%: (GetNthChild) Line 1068 File 329 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ALSTInterface.par
3,865/ 5.9%: (InitializeSingleton) Line 1757 File 346 C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
3,853/ 5.9%: (CD_GetNodeCount) Line 97 File 333 C:/DMS/Tools/CloneDR/Source/Server/Misc.par
3,853/ 5.9%: (GetNodeCountAuxiliary) Line 88 File 333 C:/DMS/Tools/CloneDR/Source/Server/Misc.par
3,829/ 5.8%: (???) Line 2367 File 3 C:/DMS/Tools/CloneDR/Source/Server/CloneDR.par
3,829/ 5.8%: (DetectClones) Line 1912 File 371 C:/DMS/Tools/CloneDR/Source/Server/TupleCloneDetector.par
3,808/ 5.8%: (AddSingletonTuple) Line 1070 File 372 C:/DMS/Tools/CloneDR/Source/Server/TupleSet.par
3,799/ 5.8%: (NewTupleSingleton) Line 1773 File 346 C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
3,733/ 5.7%: (IsListNode) Line 2137 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
3,555/ 5.4%: (ProcessTuples) Line 1710 File 371 C:/DMS/Tools/CloneDR/Source/Server/TupleCloneDetector.par
3,354/ 5.1%: (GetNthChildStandard) Line 2516 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
2,873/ 4.4%: (GetNthChildList) Line 2578 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
2,656/ 4.0%: (Subsumes?) Line 1215 File 346 C:/DMS/Tools/CloneDR/Source/Server/Tuple.par
2,624/ 4.0%: (NumberOfChildren) Line 2517 File 329 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ALSTInterface.par
2,342/ 3.6%: (IsSequenceSpine) Line 254 File 329 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ALSTInterface.par
2,159/ 3.3%: (NumberOfStandardChildren) Line 2347 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
2,017/ 3.1%: (GetNodeLiteralType) Line 5904 File 52 c:/DMS/Infrastructure/HyperGraph/Source/Graph.par
1,963/ 3.0%: (GetNodeCountFast) Line 165 File 328 C:/DMS/Tools/CloneDR/Source/Server/TreeProperties.par
1,836/ 2.8%: (NumberOfChildrenList) Line 2372 File 95 c:/DMS/Domains/DMSStringGrammar/Tools/DomainParser/Source/ASTInterface.par
1,109/ 1.7%: (AppendNewSequenceTreeToTuples) Line 656 File 371 C:/DMS/Tools/CloneDR/Source/Server/TupleCloneDetector.par
923/ 1.4%: (FindLongestSequenceExistingTupleAndNewTree) Line 368 File 371 C:/DMS/Tools/CloneDR/Source/Server/TupleCloneDetector.par
851/ 1.3%: (CreateSetOfCandidateClones) Line 1170 File 371 C:/DMS/Tools/CloneDR/Source/Server/TupleCloneDetector.par
771/ 1.2%: (FollowSequenceNodePortNthToNode) Line 5369 File 52 c:/DMS/Infrastructure/HyperGraph/Source/Graph.par
717/ 1.1%: (AppendNodeToCandidateList) Line 1101 File 371 C:/DMS/Tools/CloneDR/Source/Server/TupleCloneDetector.par
707/ 1.1%: (Lookup) Line 368 File 339 c:/DMS/Domains/PARLANSE/Library/HashTables/hash.par
这个程序在抽象语法树上爬了很多。你可以看到:热点是“GetFirstChild”(爬下树),占用了 12% 的 CPU。前 20 个函数占了大部分工作;我猜这些函数可能包含 1000 行代码。其他一切都是 1% 或更低,这是一个 500K 行的应用程序。
这只是一种测量。我认为它的性能概况总体上反映了许多应用程序。OTOH,这是对编译器数据结构的符号计算,因此它几乎不是日常计算机上运行的典型。