npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@masx200/pi-calculation-multithreading

v1.0.3

Published

Pi calculation, multithreading, based on large number frames decimal.js and webworker 圆周率计算,多线程,基于大数框架 decimal.js 和 webworker 圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架 webworker 输出 useragent 大数框架

Readme

Pi-calculation-multithreading

Pi calculation, multithreading, based on large number frames decimal.js and webworker

圆周率计算,多线程,基于大数框架 decimal.js 和 webworker

圆周率计算-可设置圆周率位数-可选择线程个数-多线程大数框架 webworker 输出 useragent 大数框架

圆周率计算多线程,使用 BigInteger.js 和浏览器原生的 BigInt 之后速度得到巨大提升!

需要浏览器 chrome68 以上,才原生支持 BigInt

可以测试浏览器的 JavaScript 运行引擎速度

建议在最新版本的 chrome 或者 Firefox 或者 safari 中运行,否则速度可能特别慢

UserAgent: Mozilla/5.0 (Linux; Android 9; MHA-AL00) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.136 Mobile Safari/537.36
开始圆周率多线程测试
线程数为 8
圆周率计算 1000 位
计算圆周率中......
计算完成,用时 1.476 秒第 340 次
圆周率 1000 位

查看算法

查看示例

在线演示

https://pi-calculation-multithreading.pages.dev/

API

类型声明

主线程中使用的计算圆周率的函数

bigintCalculatePi:使用 "big-integer"进行圆周率计算

decimalCalculatePi:使用 "decimal.js"进行圆周率计算

参数 1:创建webworker的函数

参数 2:要计算圆周率的位数

参数 3:要开启的多线程个数

返回值 1:圆周率字符串

返回值 2:计算迭代次数

主线程中关闭所有webworker的方法

bigintcleanupdecimalcleanup

子线程中添加消息事件处理程序

bigintworkersetupdecimalworkersetup

使用方法

webworker 文件中添加消息事件处理程序

import { bigintworkersetup } from "@masx200/pi-calculation-multithreading";

bigintworkersetup();

在主线程文件中

当需要关闭所有 webworker 的时候使用如下函数

import { bigintcleanup } from "@masx200/pi-calculation-multithreading";

bigintcleanup();

启动webworker并计算圆周率

import { bigintCalculatePi } from "@masx200/pi-calculation-multithreading";
import MyWorker from "./mythread1-bigint.js?worker";

//创建webworker的函数

function createworker() {
    return new MyWorker();
}
const [resultpi, x] = await bigintCalculatePi(createworker, piwei, threadgeshu);