{"id":29649798,"url":"https://github.com/iwdgo/gocompilerefficiency","last_synced_at":"2025-07-22T04:35:27.391Z","repository":{"id":57622193,"uuid":"147918221","full_name":"iwdgo/GoCompilerEfficiency","owner":"iwdgo","description":"Don't try to beat the Go compiler","archived":false,"fork":false,"pushed_at":"2019-09-24T11:59:51.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T14:25:52.086Z","etag":null,"topics":["benchmarks","efficiency","optimization","variable"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iwdgo.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}},"created_at":"2018-09-08T09:03:37.000Z","updated_at":"2019-09-24T11:59:53.000Z","dependencies_parsed_at":"2022-09-26T20:10:38.580Z","dependency_job_id":null,"html_url":"https://github.com/iwdgo/GoCompilerEfficiency","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iwdgo/GoCompilerEfficiency","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2FGoCompilerEfficiency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2FGoCompilerEfficiency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2FGoCompilerEfficiency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2FGoCompilerEfficiency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iwdgo","download_url":"https://codeload.github.com/iwdgo/GoCompilerEfficiency/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2FGoCompilerEfficiency/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266428525,"owners_count":23927012,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["benchmarks","efficiency","optimization","variable"],"created_at":"2025-07-22T04:35:26.567Z","updated_at":"2025-07-22T04:35:27.368Z","avatar_url":"https://github.com/iwdgo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/iwdgo/GoCompilerEfficiency)](https://goreportcard.com/report/github.com/iwdgo/GoCompilerEfficiency)\n\n# Benchmarking good practices\n\nGo is [strong typed and object oriented](./src/forloops/README.md) by definition.\nTo distinguish bad habits, benchmarking against the compiler performance is often convincing.\n\n***Logic***\n- The most efficient loop is using a [locally defined variable](./src/forloops/README.md)\n- Don't bother to use anything but the len() to get the [size of an array](./src/lenarray/README.md)\n- Don't duplicate code to handle the [first item of a list](./src/firstitem/README.md)\n- Don't try to [keep a single exit](./src/singleexit/README.md)\n- Always use [shadowing inside a for loop](./src/isvalid/README.md) even for a boolean.\n- Don't bother about [irrelevant cases](./src/switch/README.md) in a switch.\n- Use [bit masking](./src/bitorif/README.md) instead of a second if.\n- Get the [bits representation of a byte](./src/bytetobits/README.md) using bits package is simple and efficient.\n\n***Math***\n- math.Log2() is the most efficient to check that 2 is the [sole divisor](./src/switch/README.md). \n\n***Arrays***\n- [Array of struct](./src/arraysstruct/README.md) is as efficient as multiple arrays.\n- [Array initialization](./src/arrayinit/README.md) using append is costly.\n- Using a method is marginally more efficient to [add an element to an array](./src/arrayofarray/README.md).\n\n***Templates***\n- Use [implicit parsing for forms](src/formparse/README.md)\n- Keep a global var to hold a [template read from file](src/tmplfile/README.md)\n\n***Buffers***\n- No difference when [writing to file](src/tofile/README.md) \n- [Returning a buffer](src/returnbuffer/README.md) as a string is marginally more expensive.\n- Package `io` is much more efficient than `fmt` which offers many more possibilities:\n    - [write a simple string](src/writestring/README.md).\n    - [write a buffer to a buffer](src/writebuffer/README.md).\n- When handling every byte of a buffer, [use ReadByte](src/readbyte/README.md).\n\n***Builder***\n- No difference for a url builder between [returning the string or the url.URL](src/urlbuilder/README.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiwdgo%2Fgocompilerefficiency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiwdgo%2Fgocompilerefficiency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiwdgo%2Fgocompilerefficiency/lists"}