Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
release v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
justjavac committed Feb 3, 2021
1 parent cf5512b commit b1e0971
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["denoland.vscode-deno"]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"deno.enable": true,
"deno.unstable": true
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.2.0 - [2021-02-03]

- fix typo PrepareOptions #3

## 0.1.0 - [2020-08-21]

- first release
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@

Get the number of CPUs available on the current system.

Sometimes the CPU will exaggerate the number of CPUs it contains, because it can use [processor tricks](https://en.wikipedia.org/wiki/Simultaneous_multithreading) to deliver increased performance when there are more threads. This crate provides methods to get both the logical and physical numbers of cores.

This information can be used as a guide to how many tasks can be run in parallel. There are many properties of the system architecture that will affect parallelism, for example memory access speeds (for all the caches and RAM) and the physical architecture of the processor, so the number of CPUs should be used as a rough guide only.
Sometimes the CPU will exaggerate the number of CPUs it contains, because it can
use
[processor tricks](https://en.wikipedia.org/wiki/Simultaneous_multithreading) to
deliver increased performance when there are more threads. This crate provides
methods to get both the logical and physical numbers of cores.

This information can be used as a guide to how many tasks can be run in
parallel. There are many properties of the system architecture that will affect
parallelism, for example memory access speeds (for all the caches and RAM) and
the physical architecture of the processor, so the number of CPUs should be used
as a rough guide only.

## Usage

```ts
import num_cpus from "https://deno.land/x/num_cpus/mod.ts";
import numCpus from "https://deno.land/x/num_cpus/mod.ts";

num_cpus();
numCpus();
// => 8
```

Expand All @@ -32,4 +40,5 @@ deno run -A --unstable https://deno.land/x/num_cpus/example.ts

### License

[deno_num_cpus](https://github.com/justjavac/deno_num_cpus) is released under the MIT License. See the bundled [LICENSE](./LICENSE) file for details.
[deno_num_cpus](https://github.com/justjavac/deno_num_cpus) is released under
the MIT License. See the bundled [LICENSE](./LICENSE) file for details.
4 changes: 2 additions & 2 deletions example.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import num_cpus from "./mod.ts";
import numCpus from "./mod.ts";

const nums = num_cpus();
const nums = numCpus();
console.log(nums);
15 changes: 6 additions & 9 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {
prepare,
PrepareOptions,
} from "https://deno.land/x/plugin_prepare/mod.ts";
import { Plug } from "https://deno.land/x/plug/mod.ts";

export const PLUGIN_VERSION = "v0.1.1";
const releaseUrl =
`https://github.com/justjavac/deno_plugin_num_cpus/releases/download/${PLUGIN_VERSION}`;

const pluginOptions: PrepareOptions = {
const options: Plug.Options = {
name: "deno_plugin_num_cpus",
urls: {
linux: `${releaseUrl}/libdeno_plugin_num_cpus.so`,
Expand All @@ -23,7 +20,7 @@ let pluginId: number | null = null;
*/
async function load() {
unload();
pluginId = await prepare(pluginOptions);
pluginId = await Plug.prepare(options);
}

/**
Expand All @@ -42,13 +39,13 @@ function unload(): void {
* ```ts
* ```
*/
export default function num_cpus(): number {
export default function numCpus(): number {
// deno-lint-ignore ban-ts-comment
//@ts-ignore
const { op_num_cpus } = Deno.core.ops();
const { op_num_cpus: opNumCpus } = Deno.core.ops();
// deno-lint-ignore ban-ts-comment
//@ts-ignore
const response: Uint8Array = Deno.core.dispatch(op_num_cpus)!;
const response: Uint8Array = Deno.core.dispatch(opNumCpus)!;
return response[0];
}

Expand Down
8 changes: 3 additions & 5 deletions mod_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {
assert,
} from "https://deno.land/std@0.68.0/testing/asserts.ts";
import { assert } from "https://deno.land/std@0.68.0/testing/asserts.ts";

import num_cpus from "./mod.ts";
import numCpus from "./mod.ts";

Deno.test("cpus is greater than 1", function () {
assert(num_cpus() >= 1);
assert(numCpus() >= 1);
});

0 comments on commit b1e0971

Please sign in to comment.