early/readme.md

115 lines
5.1 KiB
Markdown
Raw Normal View History

2023-08-22 18:37:45 +00:00
# @push.rocks/early
2020-05-14 12:57:06 +00:00
minimal and fast loading plugin for startup time measuring
2024-04-14 11:35:03 +00:00
## Install
To install `@push.rocks/early`, run the following command in your terminal:
```bash
npm install @push.rocks/early --save
```
This will add `@push.rocks/early` to your project's dependencies and prepare it for use.
2020-05-14 12:57:06 +00:00
## Usage
2024-04-14 11:35:03 +00:00
In this guide, we'll explore how to use `@push.rocks/early` to measure startup times in your application. This tool is designed to be minimal and fast, providing accurate measurements of how long it takes for parts of your application to load.
### Getting Started with `@push.rocks/early`
First, ensure that your project is set up with TypeScript and that you are familiar with working with ES modules. `@push.rocks/early` is built with TypeScript in mind, offering excellent IntelliSense support in compatible editors.
#### Importing `@push.rocks/early`
To begin, import the library into your module:
```typescript
import * as early from '@push.rocks/early';
```
#### Starting Measurement
2020-08-10 21:18:50 +00:00
2024-04-14 11:35:03 +00:00
The first step in using `@push.rocks/early` is to start the measurement. This should be done as early as possible in your application's startup sequence:
```typescript
2020-08-10 21:18:50 +00:00
early.start('myModuleName');
2024-04-14 11:35:03 +00:00
```
Replace `'myModuleName'` with a string identifier for the module or application part you are measuring. This is purely for identification purposes and aids in debugging or logging.
#### Performing Your Loading Operations
After starting the measurement, proceed with the operations or loading tasks you wish to measure. This could involve loading modules, reading files, or any setup tasks required for your application to start:
```typescript
// Example loading operations
await myModule.initialize();
await myOtherModule.loadConfig();
```
#### Stopping Measurement and Retrieving Results
Once your loading operations are complete, stop the measurement to retrieve the loading time:
```typescript
2020-08-10 21:18:50 +00:00
early.stop().then((loadingTime: number) => {
2024-04-14 11:35:03 +00:00
console.log(`Loading time: ${loadingTime} milliseconds`);
});
```
This will output the total loading time in milliseconds, giving you a precise measure of the startup performance.
### Advanced Features
`@push.rocks/early` allows for more advanced use cases, such as measuring multiple segments individually or in parallel. Each `start` can be matched with a corresponding `stop` to measure different parts of your application independently:
```typescript
early.start('partOne');
// Load operations for part one...
early.stop().then((time: number) => console.log(`Part one loading time: ${time}`));
early.start('partTwo');
// Load operations for part two...
early.stop().then((time: number) => console.log(`Part two loading time: ${time}`));
```
### High Resolution Time Measurement Class
For more granular control or to measure very short operations, `@push.rocks/early` offers a `HrtMeasurement` class for high-resolution time measurements:
```typescript
import { HrtMeasurement } from '@push.rocks/early';
const hrtMeasurement = new HrtMeasurement();
hrtMeasurement.start();
// perform short duration tasks
hrtMeasurement.stop();
console.log(`Operation took ${hrtMeasurement.milliSeconds} milliseconds`);
2020-08-10 21:18:50 +00:00
```
2020-05-14 12:57:06 +00:00
2024-04-14 11:35:03 +00:00
This can be particularly useful for micro-benchmarks or when measuring the performance impact of optimization efforts.
### Conclusion
`@push.rocks/early` is a powerful yet minimalistic tool for measuring startup times and performance in Node.js applications. Its straightforward API, coupled with TypeScript support, makes it an excellent choice for developers looking to optimize their applications or simply understand their loading characteristics better.
By integrating `@push.rocks/early` into your development process, you can gain valuable insights into your application's performance, helping you make informed decisions about optimizations and improvements.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
2020-05-14 12:57:06 +00:00
2024-04-14 11:35:03 +00:00
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
2020-05-14 12:57:06 +00:00
2024-04-14 11:35:03 +00:00
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
2020-05-14 12:57:06 +00:00
2024-04-14 11:35:03 +00:00
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.