Files
archived-tauri/bench/tests/cpu_intensive/public/worker.js
Amr Bashir 36eee37220 Restructure the repository (#10796)
* Restructure the repository

* lock file

* fmt

* fix bench

* fix cli template test

* remove accidental file

* fix mv command

* clippy

* upgrade paths-filter github action

* fix cli migration tests

* lockfile

* license headers

* clippy

* scope test-core to tauri crate

* license header

* correct --manifest-path usage

* lockfile

* fix tauri-driver on macOS [skip ci]

* build target ios

* try downgrade env_logger

* downgrade 0.1.7

* try to fix bench

* bench overflow

* revert overflow fix, fix tauri_root_path

* revert env_logger downgrade

* fmt

* raise msrv to 1.71

* fmt

* delete .cargo/config.toml [skip ci]

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
2024-08-27 18:42:30 -03:00

50 lines
977 B
JavaScript

// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
const isPrime = (number) => {
if (number % 2 === 0 && number > 2) {
return false
}
let start = 2
const limit = Math.sqrt(number)
while (start <= limit) {
if (number % start++ < 1) {
return false
}
}
return number > 1
}
addEventListener('message', (e) => {
const { startTime } = e.data
let n = 0
let total = 0
const THRESHOLD = e.data.value
const primes = []
let previous = startTime
while (++n <= THRESHOLD) {
if (isPrime(n)) {
primes.push(n)
total++
const now = Date.now()
if (now - previous > 250) {
previous = now
postMessage({
status: 'calculating',
count: total,
time: Date.now() - startTime
})
}
}
}
postMessage({ status: 'done', count: total, time: Date.now() - startTime })
})