@@ -24,18 +24,18 @@ func BenchmarkParseSampleFile(b *testing.B) {
24
24
b .ResetTimer ()
25
25
for i := 0 ; i < b .N ; i ++ {
26
26
p := & Parser {
27
- minLength : 3 ,
28
- minOccurrences : 2 ,
29
- supportedTokens : []token.Token {token .STRING },
30
- excludeTypes : map [Type ]bool {},
31
- strs : Strings {},
32
- consts : Constants {},
33
- matchConstant : true ,
27
+ minLength : 3 ,
28
+ minOccurrences : 2 ,
29
+ supportedTokens : []token.Token {token .STRING },
30
+ excludeTypes : map [Type ]bool {},
31
+ strs : Strings {},
32
+ consts : Constants {},
33
+ matchConstant : true ,
34
34
evalConstExpressions : false , // Disable for benchmark
35
- stringCount : make (map [string ]int ),
36
- stringMutex : sync.RWMutex {},
37
- stringCountMutex : sync.RWMutex {},
38
- constMutex : sync.RWMutex {},
35
+ stringCount : make (map [string ]int ),
36
+ stringMutex : sync.RWMutex {},
37
+ stringCountMutex : sync.RWMutex {},
38
+ constMutex : sync.RWMutex {},
39
39
}
40
40
41
41
v := & treeVisitor {
@@ -57,9 +57,9 @@ func BenchmarkRun(b *testing.B) {
57
57
}
58
58
59
59
config := & Config {
60
- MinStringLength : 3 ,
61
- MinOccurrences : 2 ,
62
- MatchWithConstants : true ,
60
+ MinStringLength : 3 ,
61
+ MinOccurrences : 2 ,
62
+ MatchWithConstants : true ,
63
63
EvalConstExpressions : false , // Disable for benchmark
64
64
}
65
65
@@ -521,14 +521,14 @@ func BenchmarkParseTreeWithConstMatch(b *testing.B) {
521
521
// BenchmarkStringInterning benchmarks the performance improvement from string interning
522
522
func BenchmarkStringInterning (b * testing.B ) {
523
523
b .ReportAllocs ()
524
-
524
+
525
525
// Generate some test data
526
526
testData := make ([]string , 100 )
527
527
for i := 0 ; i < 100 ; i ++ {
528
528
// Create strings that will sometimes be duplicates
529
529
testData [i ] = fmt .Sprintf ("test-string-%d" , i % 20 )
530
530
}
531
-
531
+
532
532
b .ResetTimer ()
533
533
for i := 0 ; i < b .N ; i ++ {
534
534
p := New (
@@ -546,12 +546,12 @@ func BenchmarkStringInterning(b *testing.B) {
546
546
2 ,
547
547
nil ,
548
548
)
549
-
549
+
550
550
// Simulate processing these strings
551
551
for _ , s := range testData {
552
552
// Intern the string
553
553
interned := InternString (s )
554
-
554
+
555
555
// Do something with the interned string to prevent optimization
556
556
if len (interned ) > 0 {
557
557
p .stringCount [interned ]++
@@ -566,20 +566,20 @@ func BenchmarkParseTreeLargeCodebase(b *testing.B) {
566
566
if os .Getenv ("CI" ) != "true" && os .Getenv ("BENCH_LARGE" ) != "1" {
567
567
b .Skip ("Skipping large benchmark; run with BENCH_LARGE=1 to enable" )
568
568
}
569
-
569
+
570
570
// Use the parent directory of the current workspace as test data
571
571
// This gives us a real-world codebase to analyze
572
572
wd , err := os .Getwd ()
573
573
if err != nil {
574
574
b .Fatalf ("Failed to get working directory: %v" , err )
575
575
}
576
-
576
+
577
577
// Go up one level to get parent directory
578
578
testPath := filepath .Dir (wd )
579
-
579
+
580
580
b .ReportAllocs ()
581
581
b .ResetTimer ()
582
-
582
+
583
583
for i := 0 ; i < b .N ; i ++ {
584
584
p := New (
585
585
testPath ,
@@ -606,15 +606,15 @@ func BenchmarkParseTreeLargeCodebase(b *testing.B) {
606
606
// BenchmarkStringPooling benchmarks the performance impact of string pooling
607
607
func BenchmarkStringPooling (b * testing.B ) {
608
608
b .ReportAllocs ()
609
-
609
+
610
610
// Create a set of strings to process with some duplication
611
611
testStrings := make ([]string , 10000 )
612
612
for i := 0 ; i < len (testStrings ); i ++ {
613
613
testStrings [i ] = fmt .Sprintf ("test-string-%d" , i % 500 )
614
614
}
615
-
615
+
616
616
b .ResetTimer ()
617
-
617
+
618
618
for i := 0 ; i < b .N ; i ++ {
619
619
p := New (
620
620
"" ,
@@ -631,13 +631,13 @@ func BenchmarkStringPooling(b *testing.B) {
631
631
2 ,
632
632
nil , // No type exclusions
633
633
)
634
-
634
+
635
635
// Simulate processing all strings
636
636
for _ , s := range testStrings {
637
637
// Use intern to ensure string deduplication
638
638
internedString := InternString (s )
639
639
p .stringCount [internedString ]++
640
-
640
+
641
641
// Simulate position tracking (simplified)
642
642
if _ , ok := p .strs [internedString ]; ! ok {
643
643
p .strs [internedString ] = make ([]ExtendedPos , 0 , 4 )
@@ -650,14 +650,14 @@ func BenchmarkStringPooling(b *testing.B) {
650
650
func BenchmarkParallelProcessing (b * testing.B ) {
651
651
// Use the testdata directory which should have multiple files
652
652
testPath := filepath .Join ("." , "testdata" )
653
-
653
+
654
654
// Ensure the test directory exists
655
655
if _ , err := os .Stat (testPath ); os .IsNotExist (err ) {
656
656
b .Skipf ("Test data directory %q does not exist" , testPath )
657
657
}
658
-
658
+
659
659
b .ReportAllocs ()
660
-
660
+
661
661
for i := 0 ; i < b .N ; i ++ {
662
662
b .StopTimer ()
663
663
p := New (
0 commit comments