{"id":19168101,"url":"https://github.com/masx200/pi-calculation-multithreading","last_synced_at":"2025-05-07T14:12:47.068Z","repository":{"id":37956486,"uuid":"186083676","full_name":"masx200/Pi-calculation-multithreading","owner":"masx200","description":"Pi calculation, multithreading, based on large number frames decimal.js and webworker 圆周率计算，多线程，基于大数框架decimal.js和webworker 圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架webworker输出useragent大数框架","archived":false,"fork":false,"pushed_at":"2023-02-17T18:00:27.000Z","size":1146,"stargazers_count":5,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-07T14:12:37.633Z","etag":null,"topics":["biginteger-bigint","pi-calculation","webworker"],"latest_commit_sha":null,"homepage":"https://pi-calculation-multithreading.pages.dev/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/masx200.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":"2019-05-11T03:35:38.000Z","updated_at":"2023-03-14T04:32:02.000Z","dependencies_parsed_at":"2023-02-14T20:00:44.987Z","dependency_job_id":null,"html_url":"https://github.com/masx200/Pi-calculation-multithreading","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masx200%2FPi-calculation-multithreading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masx200%2FPi-calculation-multithreading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masx200%2FPi-calculation-multithreading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masx200%2FPi-calculation-multithreading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/masx200","download_url":"https://codeload.github.com/masx200/Pi-calculation-multithreading/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252892504,"owners_count":21820648,"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":["biginteger-bigint","pi-calculation","webworker"],"created_at":"2024-11-09T09:41:13.645Z","updated_at":"2025-05-07T14:12:47.046Z","avatar_url":"https://github.com/masx200.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pi-calculation-multithreading\n\nPi calculation, multithreading, based on large number frames decimal.js and webworker\n\n圆周率计算，多线程，基于大数框架 decimal.js 和 webworker\n\n圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架 webworker 输出 useragent 大数框架\n\n# 圆周率计算多线程,使用 BigInteger.js 和浏览器原生的 BigInt 之后速度得到巨大提升!\n\n需要浏览器 chrome68 以上,才原生支持 BigInt\n\n\u003ch3\u003eBigInteger.js\u003c/h3\u003e\n\u003cp\u003e\n  BigInteger.js是Javascript的任意长度整数库，允许对无限大小的整数进行算术运算，尽管存在内存和时间限制。\n  更新（2018年12月2日）：BigInt被添加为JavaScript的本机功能。\n  此库现在可用作polyfill：如果环境支持本机BigInt，则此库充当本机实现的瘦包装器。\n  建议升级浏览器到chrome68以上,才可支持原生BigInt.\n\u003cb\u003e如果浏览器原生支持BigInt,则运行速度有巨大提升!\u003c/b\u003e\n\u003c/p\u003e\n\n\u003ch3\u003e计算运行速度排行:\u003c/h3\u003e\n\u003cbr /\u003e1.原生BigInt最快,\u003cbr /\u003e2.BigInteger.js中速,\u003cbr /\u003e3.Decimal.js最慢。\n\u003chr\u003e\n\u003cbr /\u003e\n\u003ch4\u003e 线程数为4 圆周率计算6000位测试结果\u003c/h4\u003e\n\u003cbr /\u003e\nfirefox 66 测试 decimal.js 达到1倍速度\n\u003cbr /\u003e\nfirefox 66 测试 BigInteger.js 达到2.163倍速度\n\u003cbr /\u003e\nchrome 75 测试 decimal.js 达到3.4375倍速度\n\u003cbr /\u003e\nchrome 75 测试 原生BigInt 达到74.038倍速度\n\u003cp\u003e\u003c/p\u003e\n\u003chr\u003e\n\u003ch4\u003e 线程数为4 圆周率计算10000位测试结果\u003c/h4\u003e\n\u003cbr /\u003e\nfirefox 66 测试 decimal.js 达到1倍速度\n\u003cbr /\u003e\nfirefox 66 测试 BigInteger.js 达到2.066倍速度\n\u003cbr /\u003e\nchrome 75 测试 decimal.js 达到3.688倍速度\n\u003cbr /\u003e\nchrome 75 测试 原生BigInt 达到100.773倍速度\n\u003cp\u003e\u003c/p\u003e\n\u003chr\u003e\n\n可以测试浏览器的 JavaScript 运行引擎速度\n\n建议在最新版本的 chrome 或者 Firefox 或者 safari 中运行，否则速度可能特别慢\n\n```\nUserAgent: Mozilla/5.0 (Linux; Android 9; MHA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.136 Mobile Safari/537.36\n开始圆周率多线程测试\n线程数为 8\n圆周率计算 1000 位\n计算圆周率中......\n计算完成,用时 1.476 秒第 340 次\n圆周率 1000 位\n```\n\n[查看算法](src/pi_calc.AsciiMath)\n\n[查看示例](src/index.html)\n\n# 在线演示\n\nhttps://pi-calculation-multithreading.pages.dev/\n\n# API\n\n[类型声明](src/index.ts)\n\n## 主线程中使用的计算圆周率的函数\n\n`bigintCalculatePi`:使用 \"big-integer\"进行圆周率计算\n\n`decimalCalculatePi`:使用 \"decimal.js\"进行圆周率计算\n\n参数 1:创建`webworker`的函数\n\n参数 2:要计算圆周率的位数\n\n参数 3:要开启的多线程个数\n\n返回值 1:圆周率字符串\n\n返回值 2:计算迭代次数\n\n## 主线程中关闭所有`webworker`的方法\n\n`bigintcleanup`和`decimalcleanup`\n\n## 子线程中添加消息事件处理程序\n\n`bigintworkersetup`和`decimalworkersetup`\n\n# 使用方法\n\n## 在 `webworker` 文件中添加消息事件处理程序\n\n```js\nimport { bigintworkersetup } from \"@masx200/pi-calculation-multithreading\";\n\nbigintworkersetup();\n```\n\n## 在主线程文件中\n\n### 当需要关闭所有 `webworker` 的时候使用如下函数\n\n```js\nimport { bigintcleanup } from \"@masx200/pi-calculation-multithreading\";\n\nbigintcleanup();\n```\n\n### 启动`webworker`并计算圆周率\n\n```js\nimport { bigintCalculatePi } from \"@masx200/pi-calculation-multithreading\";\nimport MyWorker from \"./mythread1-bigint.js?worker\";\n\n//创建webworker的函数\n\nfunction createworker() {\n    return new MyWorker();\n}\n```\n\n```js\nconst [resultpi, x] = await bigintCalculatePi(createworker, piwei, threadgeshu);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasx200%2Fpi-calculation-multithreading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasx200%2Fpi-calculation-multithreading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasx200%2Fpi-calculation-multithreading/lists"}