From 4f6d3240232bafa7a6372c3a9e9a0c715c030e5c Mon Sep 17 00:00:00 2001 From: apocelipes Date: Wed, 8 Jan 2025 17:12:11 +0800 Subject: [PATCH] Use a faster method to convert ints to strings --- SCC-OUTPUT-REPORT.html | 14 +++++------ cmd/badges/simplecache_test.go | 16 ++++++------ processor/formatters.go | 46 +++++++++++++++++----------------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/SCC-OUTPUT-REPORT.html b/SCC-OUTPUT-REPORT.html index 5cb4c67f..64c6b8d6 100644 --- a/SCC-OUTPUT-REPORT.html +++ b/SCC-OUTPUT-REPORT.html @@ -18,8 +18,8 @@ 447 7678 1413 - 256008 - 4131 + 256040 + 4138 processor/workers_test.go @@ -38,8 +38,8 @@ 39 1272 163 - 44359 - 783 + 44422 + 790 processor/formatters_test.go @@ -198,7 +198,7 @@ 3 78 17 - 2030 + 1999 53 processor/structs_test.go @@ -299,8 +299,8 @@ 447 7678 1413 - 256008 - 4131 + 256040 + 4138 Estimated Cost to Develop (organic) $229,670
Estimated Schedule Effort (organic) 7.86 months
Estimated People Required (organic) 2.59
diff --git a/cmd/badges/simplecache_test.go b/cmd/badges/simplecache_test.go index 497a4b5a..ad530ab9 100644 --- a/cmd/badges/simplecache_test.go +++ b/cmd/badges/simplecache_test.go @@ -1,7 +1,7 @@ package main import ( - "fmt" + "strconv" "sync" "testing" "time" @@ -11,12 +11,12 @@ func TestSimpleCache_Add(t *testing.T) { simpleCache := NewSimpleCache(5, 60) for i := 0; i < 5; i++ { - simpleCache.Add(fmt.Sprintf("%d", i), []byte{}) + simpleCache.Add(strconv.Itoa(i), []byte{}) } for i := 0; i < 4; i++ { for j := 0; j < 5; j++ { - simpleCache.Get(fmt.Sprintf("%d", i)) + simpleCache.Get(strconv.Itoa(i)) } } @@ -27,7 +27,7 @@ func TestSimpleCache_Multiple(t *testing.T) { simpleCache := NewSimpleCache(10, 60) for i := 0; i < 500; i++ { - simpleCache.Add(fmt.Sprintf("%d", i), []byte{}) + simpleCache.Add(strconv.Itoa(i), []byte{}) } simpleCache.Add("test-key", []byte{}) @@ -41,9 +41,9 @@ func TestSimpleCache_MultipleLarge(t *testing.T) { simpleCache := NewSimpleCache(1000, 60) for i := 0; i < 500000; i++ { - simpleCache.Add(fmt.Sprintf("%d", i), []byte{}) + simpleCache.Add(strconv.Itoa(i), []byte{}) simpleCache.Add("10", []byte{}) - simpleCache.Get(fmt.Sprintf("%d", i)) + simpleCache.Get(strconv.Itoa(i)) simpleCache.Get("10") simpleCache.Get("10") } @@ -65,7 +65,7 @@ func TestSimpleCache_AgeOut(t *testing.T) { } for i := 0; i < 10; i++ { - simpleCache.Add(fmt.Sprintf("%d", i), []byte{}) + simpleCache.Add(strconv.Itoa(i), []byte{}) } // advance time @@ -86,7 +86,7 @@ func TestSimpleCache_AgeOutTime(t *testing.T) { simpleCache := NewSimpleCache(100, 1) for i := 0; i < 10; i++ { - simpleCache.Add(fmt.Sprintf("%d", i), []byte{}) + simpleCache.Add(strconv.Itoa(i), []byte{}) } time.Sleep(1 * time.Second) diff --git a/processor/formatters.go b/processor/formatters.go index 3800a339..5da87900 100644 --- a/processor/formatters.go +++ b/processor/formatters.go @@ -305,14 +305,14 @@ func toCSVSummary(input chan *FileJob) string { for _, result := range language { records = append(records, []string{ result.Name, - fmt.Sprint(result.Lines), - fmt.Sprint(result.Code), - fmt.Sprint(result.Comment), - fmt.Sprint(result.Blank), - fmt.Sprint(result.Complexity), - fmt.Sprint(result.Bytes), - fmt.Sprint(result.Count), - fmt.Sprint(len(ulocLanguageCount[result.Name])), + strconv.FormatInt(result.Lines, 10), + strconv.FormatInt(result.Code, 10), + strconv.FormatInt(result.Comment, 10), + strconv.FormatInt(result.Blank, 10), + strconv.FormatInt(result.Complexity, 10), + strconv.FormatInt(result.Bytes, 10), + strconv.FormatInt(result.Count, 10), + strconv.Itoa(len(ulocLanguageCount[result.Name])), }) } @@ -403,13 +403,13 @@ func toCSVFiles(input chan *FileJob) string { result.Language, result.Location, result.Filename, - fmt.Sprint(result.Lines), - fmt.Sprint(result.Code), - fmt.Sprint(result.Comment), - fmt.Sprint(result.Blank), - fmt.Sprint(result.Complexity), - fmt.Sprint(result.Bytes), - fmt.Sprint(result.Uloc), + strconv.FormatInt(result.Lines, 10), + strconv.FormatInt(result.Code, 10), + strconv.FormatInt(result.Comment, 10), + strconv.FormatInt(result.Blank, 10), + strconv.FormatInt(result.Complexity, 10), + strconv.FormatInt(result.Bytes, 10), + strconv.Itoa(result.Uloc), }) } @@ -493,17 +493,17 @@ func toCSVStream(input chan *FileJob) string { var location = "\"" + quoteRegex.ReplaceAllString(result.Location, "\"\"") + "\"" var filename = "\"" + quoteRegex.ReplaceAllString(result.Filename, "\"\"") + "\"" - fmt.Printf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", + fmt.Printf("%s,%s,%s,%d,%d,%d,%d,%d,%d,%d\n", result.Language, location, filename, - fmt.Sprint(result.Lines), - fmt.Sprint(result.Code), - fmt.Sprint(result.Comment), - fmt.Sprint(result.Blank), - fmt.Sprint(result.Complexity), - fmt.Sprint(result.Bytes), - fmt.Sprint(result.Uloc), + result.Lines, + result.Code, + result.Comment, + result.Blank, + result.Complexity, + result.Bytes, + result.Uloc, ) }