{"id":18053996,"url":"https://github.com/hymkor/go-bench-make-with-cap","last_synced_at":"2025-04-05T08:22:18.959Z","repository":{"id":82954674,"uuid":"597314740","full_name":"hymkor/go-bench-make-with-cap","owner":"hymkor","description":"benchmark between make with capacity vs append n-times","archived":false,"fork":false,"pushed_at":"2023-02-04T06:32:41.000Z","size":3,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-10T15:50:58.590Z","etag":null,"topics":["benchmark","go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hymkor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-04T06:31:04.000Z","updated_at":"2023-03-05T02:37:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"336ede86-0f2b-4ee3-ba38-db5bdcf93778","html_url":"https://github.com/hymkor/go-bench-make-with-cap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-bench-make-with-cap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-bench-make-with-cap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-bench-make-with-cap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hymkor%2Fgo-bench-make-with-cap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hymkor","download_url":"https://codeload.github.com/hymkor/go-bench-make-with-cap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247307384,"owners_count":20917457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","go"],"created_at":"2024-10-31T00:08:45.987Z","updated_at":"2025-04-05T08:22:18.936Z","avatar_url":"https://github.com/hymkor.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Report for benchmark between make with capacity vs append n-times\r\n=================================================================\r\n\r\n1. `[]string{}` and `append` N-times\r\n2. `make([]string,0,N)` and `append` N-times\r\n3. `make([]string,N)` and no `append` (access with index)\r\n\r\nThis repository also serves as your own template for how to take benchmarks\r\n\r\nSource\r\n------\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n    \"fmt\"\r\n    \"testing\"\r\n)\r\n\r\nfunc BenchmarkAppendN(b *testing.B) {\r\n    buffer := []string{}\r\n    b.ResetTimer()\r\n    for i := 0; i \u003c b.N; i++ {\r\n        buffer = append(buffer, fmt.Sprintf(\"%d\", i))\r\n    }\r\n}\r\n\r\nfunc BenchmarkMakeWithCapAndAppend(b *testing.B) {\r\n    buffer := make([]string, 0, b.N)\r\n    b.ResetTimer()\r\n    for i := 0; i \u003c b.N; i++ {\r\n        buffer = append(buffer, fmt.Sprintf(\"%d\", i))\r\n    }\r\n}\r\n\r\nfunc BenchmarkNoAppend(b *testing.B) {\r\n    buffer := make([]string, b.N)\r\n    b.ResetTimer()\r\n    for i := 0; i \u003c b.N; i++ {\r\n        buffer[i] = fmt.Sprintf(\"%d\", i)\r\n    }\r\n}\r\n```\r\n\r\nResult\r\n------\r\n\r\n```\r\ngo fmt\r\ngo test -bench . -benchmem\r\ngoos: windows\r\ngoarch: amd64\r\npkg: github.com/hymkor/go-bench-make-with-cap\r\ncpu: Intel(R) Core(TM) i5-6500T CPU @ 2.50GHz\r\nBenchmarkAppendN-4                   5515822           237.3 ns/op       111 B/op          1 allocs/op\r\nBenchmarkMakeWithCapAndAppend-4      9754629           125.8 ns/op        15 B/op          1 allocs/op\r\nBenchmarkNoAppend-4                  9762398           125.3 ns/op        15 B/op          1 allocs/op\r\nPASS\r\nok      github.com/hymkor/go-bench-make-with-cap    5.728s\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhymkor%2Fgo-bench-make-with-cap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhymkor%2Fgo-bench-make-with-cap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhymkor%2Fgo-bench-make-with-cap/lists"}