decorative-profiler
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

decorative-profiler

Summary

A method, function and block profiler that supports typescript decorators!

how to use

SCROLL DOWN FOR JAVASCRIPT

also, all parameter combinations and thinkable types are supported even if not used for the below showcases.

using typescript annotations you can do:

import {Profile, clear} from 'decorative-profiler'
 
class Abc {
 
        myField = 10
 
        @Profile() // will be accessible with myMethod as name
        myMethod() {
            return 1 + 2 + this.myField
        }
        
        @Profile("customName") //will be accessible with customName
        myMethod2() {
            return 1 + 2 + this.myField
        }
    }
    
    
let abc = new Abc()
 
abc.myMethod()
abc.myMethod()
 
// you can also clear measurements
clear()

and to print all or a specific summary:

import {stringSummaryAll, stringSummary} from 'decorative-profiler'
 
let summary = stringSummaryAll()
console.log(summary)
 
let singleSummary = stringSummary("yourCustomNameOrTheMethodName")
console.log(singleSummary)    

for javascript you can use the function factory:

import {profiledFunction} from 'decorative-profiler'
 
const myMethod = profiledFunction(() => {
    return 1 + 2 + this.myField
}, "myMethodName")
 
myMethod()

and to print all or a specific summary:

import {stringSummaryAll, stringSummary} from 'decorative-profiler'
 
let summary = stringSummaryAll()
console.log(summary)
 
let singleSummary = stringSummary("yourCustomNameOrTheMethodName")
console.log(singleSummary)    

example output of the summary and single summary respectively:

|myMethod2222222222222222222| callCount=4     | totalRunTime=3.472292                      | averageRunTime=0.868073                      |
|Summary                    |                 |                                            |                                              |
|myMethod                   | callCount=8     | totalRunTime=0.187811                      | averageRunTime=0.023476375                   |
|myMethod2222222222222222222| callCount=4     | totalRunTime=3.472292                      | averageRunTime=0.868073                      |
|                           | callCount=12    | sumTotalRunTime=3.660103                   |                                              |

Package Sidebar

Install

npm i decorative-profiler

Weekly Downloads

8

Version

1.2.1

License

MIT

Unpacked Size

20.8 kB

Total Files

19

Last publish

Collaborators

  • sebastiandero