feature: vor und nachteile

This commit is contained in:
Hikyu
2026-05-31 13:54:31 +02:00
parent 552a947a1c
commit e3dad17446
23270 changed files with 3024794 additions and 200 deletions
+10
View File
@@ -0,0 +1,10 @@
export default function timeSpan() {
const start = performance.now();
const end = () => performance.now() - start;
end.rounded = () => Math.round(end());
end.seconds = () => end() / 1000;
end.nanoseconds = () => end() * 1000000;
return end;
}
+46
View File
@@ -0,0 +1,46 @@
export interface TimeEndFunction {
/**
@returns Elapsed milliseconds.
*/
(): number;
/**
@returns Elapsed milliseconds rounded.
*/
rounded(): number;
/**
@returns Elapsed seconds.
*/
seconds(): number;
/**
@returns Elapsed nanoseconds.
*/
nanoseconds(): bigint;
}
/**
Simplified high resolution timing.
@returns A function that returns the time difference.
@example
```
import timeSpan from 'time-span';
const end = timeSpan();
timeConsumingFn();
console.log(end());
//=> 1745.3186
console.log(end.rounded());
//=> 1745
console.log(end.seconds());
//=> 1.7453186
```
*/
export default function timeSpan(): TimeEndFunction;
+13
View File
@@ -0,0 +1,13 @@
import convertHrtime from 'convert-hrtime';
export default function timeSpan() {
const start = process.hrtime.bigint();
const end = type => convertHrtime(process.hrtime.bigint() - start)[type];
const returnValue = () => end('milliseconds');
returnValue.rounded = () => Math.round(end('milliseconds'));
returnValue.seconds = () => end('seconds');
returnValue.nanoseconds = () => end('nanoseconds');
return returnValue;
}
+9
View File
@@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+58
View File
@@ -0,0 +1,58 @@
{
"name": "time-span",
"version": "5.1.0",
"description": "Simplified high resolution timing",
"license": "MIT",
"repository": "sindresorhus/time-span",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": {
"types": "./index.d.ts",
"node": "./index.js",
"default": "./browser.js"
},
"engines": {
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"browser.js",
"index.d.ts"
],
"keywords": [
"time",
"span",
"elapsed",
"process",
"hrtime",
"highres",
"timing",
"perf",
"performance",
"bench",
"benchmark",
"profiling",
"measure",
"seconds",
"milliseconds",
"nanoseconds"
],
"dependencies": {
"convert-hrtime": "^5.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"delay": "^5.0.0",
"in-range": "^3.0.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
+52
View File
@@ -0,0 +1,52 @@
# time-span
> Simplified high resolution timing
Uses [`process.hrtime`](https://nodejs.org/api/process.html#processhrtimebigint) in Node.js and [`performance.now`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now) in browsers ([accurate to 5 microseconds](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp)).
## Install
```
$ npm install time-span
```
## Usage
```js
import timeSpan from 'time-span';
const end = timeSpan();
timeConsumingFn();
console.log(end());
//=> 1745.3186
console.log(end.rounded());
//=> 1745
console.log(end.seconds());
//=> 1.7453186
```
## API
### `const end = timeSpan()`
Returns a function, that when called, returns the time difference.
#### end()
Elapsed milliseconds.
#### end.rounded()
Elapsed milliseconds rounded.
#### end.seconds()
Elapsed seconds.
#### end.nanoseconds()
Elapsed nanoseconds.