{"id":15331359,"url":"https://github.com/flimzy/promise-benchmarks","last_synced_at":"2026-05-08T23:02:49.480Z","repository":{"id":84919265,"uuid":"80278573","full_name":"flimzy/promise-benchmarks","owner":"flimzy","description":null,"archived":false,"fork":false,"pushed_at":"2017-01-28T11:34:12.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T05:44:22.528Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flimzy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-01-28T10:36:02.000Z","updated_at":"2017-01-28T10:36:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"0cfdde80-27d1-4099-85af-c54da71f8435","html_url":"https://github.com/flimzy/promise-benchmarks","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"fbf7446c16dccb5ab2fdfe454a2bee4df211d6ef"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flimzy%2Fpromise-benchmarks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flimzy%2Fpromise-benchmarks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flimzy%2Fpromise-benchmarks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flimzy%2Fpromise-benchmarks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flimzy","download_url":"https://codeload.github.com/flimzy/promise-benchmarks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241476458,"owners_count":19968916,"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":[],"created_at":"2024-10-01T09:55:21.312Z","updated_at":"2026-05-08T23:02:49.356Z","avatar_url":"https://github.com/flimzy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"This repo contains tests for interacting with JS Promises and callbacks from GopherJS.\n\nTo test, I created an empty promise, and an empty function which returns a callback.\n\n```\n$global.EmptyPromise = function() {\n    return new Promise(function(resolve, reject) {\n        resolve('Success!');\n    });\n};\n$global.EmptyCallback = function(resolve, reject) {\n    resolve('Success!');\n};\n```\n\nThis to ensure that I'm only testing the interaction between promises/callbacks\nand GopherJS, and as little else as possible.\n\nThen I constructed a few different ways of interacting with these functions:\n\n- Using `sync.WaitGroup` (DoPromise1 \u0026 DoCallback1)\n- Using bare channels (DoPromise2, DoCallback2, RawPromise \u0026 RawCallback)\n- Waiting in a loop (DoPromise3)\n\nUnsurprisingly, bare channels win (as the other two methods use channels in the\nbackground, with additional overhead).\n\nFurther, the `RawPromise` and `RawCallback` benchmarks attempt to benchmark\nonly the channel operation (inspired by @r-l-x's [tests](https://gopherjs.github.io/playground/#/btm0GV_mQY)\non [GopherJS PR#558](https://github.com/gopherjs/gopherjs/pull/558)). These functions\nprovide the most surprising finding to me: That even when attempting to isolate\nchannel operation, callbacks are faster than promises. Something must be wrong\nwith these tests.\n\nThe most surprising finding, for me, was that using bare callbacks were far\nmore performant, on the order of 225x faster than promises.\n\n```\nBenchmarkChannel                  500000              2968 ns/op\nBenchmarkChannelInGoroutine       300000              5056 ns/op\nBenchmarkRawPromise                 2000           1179000 ns/op\nBenchmarkRawCalback               300000              5153 ns/op\nBenchmarkDoPromise1                 2000           1213000 ns/op\nBenchmarkDoPromise2                 2000           1224000 ns/op\nBenchmarkDoPromise3                 1000           2295000 ns/op\nBenchmarkDoCallback1              200000              9760 ns/op\nBenchmarkDoCallback2              200000              6670 ns/op\n```\n\nI ran my tests using node.js v6.9.3 on Debian stretch (testing), kernel\n4.2.0-1-amd64 on a Lenovo Thinkpad T430s (Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz x 4 cores).\nI ran my benchmarks using the following command:\n\n    gopherjs test github.com/flimzy/promise --bench=.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflimzy%2Fpromise-benchmarks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflimzy%2Fpromise-benchmarks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflimzy%2Fpromise-benchmarks/lists"}