diff --git a/README.md b/README.md index 2ee535a..c47752f 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,28 @@ bench.concurrency = 'task' // The concurrency mode to determine how tasks are ru await bench.run() ``` +## Retaining Samples + +By default Tinybench does not keep the samples for `latency` and `throughput` to +minimize memory usage. Enable sample retention if you need the raw samples for +plotting, custom analysis, or exporting results. + +You can enable samples retention at the bench level by setting the +`retainSamples` option to `true` when creating a `Bench` instance: + +```ts +const bench = new Bench({ retainSamples: true }) +``` + +You can also enable samples retention by setting the `retainSamples` option to +`true` when adding a task: + +```ts +bench.add('task with samples', () => { + // Task logic here +}, { retainSamples: true }) +``` + ## Aborting Benchmarks Tinybench supports aborting benchmarks using `AbortSignal` at both the bench and task levels: diff --git a/docs/assets/hierarchy.js b/docs/assets/hierarchy.js index 5ceb25e..4e2b524 100644 --- a/docs/assets/hierarchy.js +++ b/docs/assets/hierarchy.js @@ -1 +1 @@ -window.hierarchyData = "eJydks1OwzAQhN9lzy44fy7yDbgiIRUkDlUOId4qVhy7srdcqrw7MqGhhaImvfhgz8w3a3sP3jkKINdpwllacJYJUTLwuDFYk3Y2gNxDEhdbdQgSHtDWDTBotVUgk/SOwc4bkFCbKgQMt1+Cm4Y6A2zYBAkU1CI6FsNGzyBN+O/UJ93imJwW4pCsLaHfVPUhPOr+BYzieNhoozxakOukjMziD/N5O0w5AfstnUvO+DKyM748Yq8wOPOBakaHc5YJXSI6z4/Qr1VoVxh2hu7fnSdUb5qaF6pIB9L1pRYX3BMLnbzDT+Sj67YGCdXkEqNjIliIs+Arr2D27KcfI89ZVvCy7/tPgswwLg==" \ No newline at end of file +window.hierarchyData = "eJydkjFrwzAQhf/LzUqLJGQXbW3WQiEtdAgeXOuChWUpSJcuwf+9qG5ME1Jid9Fweu9974SOEEOgBHoruGBCSSbLsmIQceewIRt8An0Eng9f9wgantA3LTDorDeguXhgcIgONDSuTgnT/bfgrqXeARuHoIGSWWXHahwMDAQXl6nPtsMpWajilGw9YdzVzSk86/4ETOJ82VpnInrQW15lppKXzJf9uOUM7I90KVlykdnybN8NpuA+0SzocM0yo0tGK/UL/VanboPp4OjxI0RC826pfaWabCLb3Gpxwz2zUMGvFlqHfu+Q0MwuMTlmgsvyKvifT7B49/OPoRSTBa+GYfgCnqkwPA==" \ No newline at end of file diff --git a/docs/assets/navigation.js b/docs/assets/navigation.js index 29685d4..d41408e 100644 --- a/docs/assets/navigation.js +++ b/docs/assets/navigation.js @@ -1 +1 @@ -window.navigationData = "eJyVlU9PAjEQxb9Lz0QEBZWbEogahGQh8WA8LMuQrSxT0s4uGuN3N7vA/i1tuc577zfTZrb78csIvokN2BNgELIW2/kUsgELIl8pUO2sfBXSNmIttuG4YoNO9/6vlecWvto0Y2nVlMqwowSQiixHArn2g1PXTK5Cur1+HTLhGzjPSFUrYrYjLlCdpxwNJlA27IQrAgQ5W35BoD+ZxmfCjtE0XK6aER5QLBFWhrHqJhPQAyWiBFbWu9MZTeA5+cQV8UCPK2QTJN08D1Qc0eNSSIKVltVwXYR85xRahrVk3NoNxXYXgf0Muc8NO5JSSCv06HJDTgXNyXe47sLoBvZiJL6FF1wLC7nkdEO7DXzRtBcthvtGFM9hiUk/u8pLWSdcP9x1el09JW1dfbgbtJPFRh0KDGIpAYOfOq0kOVCUiGDhLyMYCkxAEkgNr2mykSsPbp1YEW2kMdbjY7RnnoVoXPOhasvqki651/nxU6iHc8FGmIp987BZ0ZZMN0a/qIXiwjh8ITrGQbExUOyLcOJLnu6MaqPYV5M35VAo08uZlqPrGIPsv9XOxSqgf1vuuhBvShfOhEbw8x8SWjte" \ No newline at end of file +window.navigationData = "eJyVlV1PKjEQhv9Lr8lB8evInRKJGsUESM6F8aIsQ7ayTEk7C8cY/7vZBfazdMpt3/d9Ou1OZ9+/BcF/En1xDxjFoiPWkmLRF1EirQXbzZf/xLRKREcsFc5F/7z396dT5KbSLtuxbNWXyrEPG0AqswoJzEJGh11zuQ7pXV03IS9qCccZmcoi3takNNrjlL3BB8qLfVGWAMG8zT4hcp/M4fNhh+grrlD9iDFQahDmnrKaJh9wDFYnG5izd+cy+sATkqQsqciNK2UfJOu8Mdg0obuZNgRzJ6vlOgn5T1HMFMtkwrYb6NU6Af4MhS8M+2CMNix07wpDjjRNSAZcd2kMA49TJLWCJ1xohlxxhqHDCj6p2pMaI7wjynFYYdLXujYpm4Sz25vzq56bkm1dH9wt2sHCUQcao9QYwOirSatIARSrE5jKWQIDjRswBMbBa5s4cm3gNok1kSMNsRkfIp951Lp1zbtVLutKhuSeJ/un0AwXAkcY6W37sPkil5zIbBK1unS/zKbzSXmMURU5Uta57gdTKiGM3Ut1MXYKx0C9LcMbaVTWu7aLeltPXlRDsck+0qgaXaQY5f/PbiHWAdeX1V2n+tW6wrnQCn78AhtsaCI=" \ No newline at end of file diff --git a/docs/assets/search.js b/docs/assets/search.js index 76a8b7a..3825f79 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = "eJy1XVGP4zaS/i/qV2/HJUoU1W97uQSXw14WmAR7D43BwWOr0964pYatnkkwmP9+ECVZVWSRKsmdp56xyK9I6uNXpSqZ/pqcmy+X5OHxa/L7sT4kD5CaTVLvXqrkIfmPqt4/J5vk7XxKHpL9aXe5VJfv7Kf3z+3LKdmMHyYPSfJtM2LkkF4x9k19ac9v+7Y5R5DuaDOEukled+eqbq/DmczANs2udnaHww+fq7r9x/HSVnUVNbY7HKqu7Wlqu8Livqn3b+dzVe//nJkZarbCzrGtzrv22NSXmBnSaoUV+yeCP1xfg9x8iQLbyytwz9VL87kS3/S++Tvc9/Nb3R7jizU1WY//r+p8OTa1wMzna8sV1i5V+/YaMzI2WIN9/K3enaLgY4sV6G21Ox+aL9EVQm3WWHg+V5fn5nSImkCN1tnoBDhuoG+xBn2GqOtZ+mV3fokT59piNfpPIuXr296qfz3KrzPr1bdatGqpTiHDqnV5O7XRCU1NVllod5ff44QaGgjRt5nBXnbGsa7D/a1qf91dfo9h/1a1bd9kBX4v/vPuYS36pWpn7qhts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sCtzGHenTMCux8qhW4qdPcg4fyHCobGrB9mttGfCIQjs6kG2+MOxzYje5DltWKDRVQ83tpSp9HgoMwInGjuADyKpBxUyw/9LmYwP51KgVcAuKR1pM+oRqCuR8vEf4yN4Jrc4nlqBFAqb3cqINPx+LNpFSOZS2Q30nmnQOMYgOJOJXQfFJH2w3uWy6K9D8vW3xNTKZft4QtqNRwmiW40DGKEWe4BdVoq/pRrPXJiFneD305FjyOniXb7gDveQ1XhmEwLEe17o1CbAumkv4+kyCBPH+0KvMmEOynu0JwUhUHyv1FIacaPEGy5benfCd73Ad33BziEgKaJ6KhSD64nxSC9xpDCIcD4omR42dykc4nQYPMLHbmvQ3XzQRT14x1IWE+DzYdBikglcFffqcIXkGo6NRwPH+2hYkHzwTsWg8KXMDbuxB5CU1wA9uIhiGHgpHPd0Sg1aErzmY6gE49MwZEJRsL+si6I4hCrcDNM5r0jy8NYH2S4dj7ZHS4hRxmBwDOSGv8Uw4VI2X//YemQOS8twp/KBvcUYTSyZixvcKhS2CONPfLI9GinWrDFPMdC1GGhcCgx83CSvx9fqdKyr5OHx47dv/w8lKvPG"; \ No newline at end of file +window.searchData = "eJy1Xd+P47YR/l98r85GQ1KUtG9tmqAp2hS4C9qHxaHw2bqsE6+0sLV3CQ73vxeiKGtIDqmRvHm6ZE3OjKhvfvAbifqyObefL5v7hy+b347NYXMPotxumt1Tvbnf/LVu9o+b7eblfNrcb/an3eVSX741f7177J5Om+34x839ZvN1O8rIQVxl7Nvm0p1f9l17Tkh64w5DUreb5925brqrOZMayIS66tkdDt9/qpvun8dLVzd1UtnucKj7sadp7AqN+7bZv5zPdbP/Y+bK0LAVeo5dfd51x7a5pNQ4o1ZoMf8k5Nvf10huPycFm59XyD3XT+2nmn3Th+GvcN/Pdbc7Nu92T8+nOnlLhoGX68A1ul6a7pi+MdOQ9fL/U58vx7ZhqPl0HblC26XuXp5TSsYBa2Qff2l2p6TwccQK6V29Ox/az8kVQmPWaHg815fH9nRIqkCD1unog31awTB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s/classes/Bench.html index a51c874..9d2fe54 100644 --- a/docs/classes/Bench.html +++ b/docs/classes/Bench.html @@ -1,11 +1,12 @@ Bench | tinybench - v5.1.0
tinybench - v5.1.0
    Preparing search index...

    Class Bench

    The Bench class keeps track of the benchmark tasks and controls them.

    -

    Hierarchy

    • EventTarget
      • Bench

    Implements

    Index

    Constructors

    Hierarchy

    • EventTarget
      • Bench

    Implements

    Index

    Constructors

    Properties

    addEventListener: <K extends BenchEvents>(
        type: K,
        listener: EventListener<K> | EventListenerObject<K, "bench"> | null,
        options?: boolean | AddEventListenerOptions,
    ) => void

    The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

    +

    Constructors

    Properties

    addEventListener: <K extends BenchEvents>(
        type: K,
        listener: EventListener<K> | EventListenerObject<K, "bench"> | null,
        options?: boolean | AddEventListenerOptions,
    ) => void

    The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

    MDN Reference

    -
    concurrency: "task" | "bench" | null = null

    Executes tasks concurrently based on the specified concurrency mode.

    +
    concurrency: "task" | "bench" | null = null

    Executes tasks concurrently based on the specified concurrency mode.

    • When mode is set to null (default), concurrency is disabled.
    • When mode is set to 'task', each task's iterations (calls of a task function) run concurrently.
    • When mode is set to 'bench', different tasks within the bench run concurrently.
    -
    iterations: number

    The amount of executions per task.

    -
    name: string | undefined

    The benchmark name.

    -
    now: () => number

    A function to get a timestamp.

    -
    removeEventListener: <K extends BenchEvents>(
        type: K,
        listener: EventListener<K> | EventListenerObject<K, "bench"> | null,
        options?: boolean | EventListenerOptions,
    ) => void

    Removes a previously registered event listener.

    -
    runtime: JSRuntime

    The JavaScript runtime environment.

    -
    runtimeVersion: string

    The JavaScript runtime version.

    -
    setup: (task: Task, mode: "warmup" | "run") => void | Promise<void>

    A setup function that runs before each task execution.

    -
    signal: AbortSignal | undefined

    An AbortSignal to cancel the benchmark.

    -
    teardown: (task: Task, mode: "warmup" | "run") => void | Promise<void>

    A teardown function that runs after each task execution.

    -
    threshold: number = Infinity

    The maximum number of concurrent tasks to run

    +
    iterations: number

    The amount of executions per task.

    +
    name: string | undefined

    The benchmark name.

    +
    now: () => number

    A function to get a timestamp.

    +
    removeEventListener: <K extends BenchEvents>(
        type: K,
        listener: EventListener<K> | EventListenerObject<K, "bench"> | null,
        options?: boolean | EventListenerOptions,
    ) => void

    Removes a previously registered event listener.

    +
    retainSamples: boolean

    Should samples be retained for further custom processing

    +
    runtime: JSRuntime

    The JavaScript runtime environment.

    +
    runtimeVersion: string

    The JavaScript runtime version.

    +
    setup: (task: Task, mode: "warmup" | "run") => void | Promise<void>

    A setup function that runs before each task execution.

    +
    signal: AbortSignal | undefined

    An AbortSignal to cancel the benchmark.

    +
    teardown: (task: Task, mode: "warmup" | "run") => void | Promise<void>

    A teardown function that runs after each task execution.

    +
    threshold: number = Infinity

    The maximum number of concurrent tasks to run

    Infinity
     
    -
    throws: boolean

    Whether to throw an error if a task function throws

    +
    throws: boolean

    Whether to throw an error if a task function throws

    false
     
    -
    time: number

    The amount of time to run each task.

    -
    warmup: boolean

    Whether to warmup the tasks before running them

    -
    warmupIterations: number

    The amount of warmup iterations per task.

    -
    warmupTime: number

    The amount of time to warmup each task.

    -

    Accessors

    time: number

    The amount of time to run each task.

    +
    warmup: boolean

    Whether to warmup the tasks before running them

    +
    warmupIterations: number

    The amount of warmup iterations per task.

    +
    warmupTime: number

    The amount of time to warmup each task.

    +

    Accessors

    Methods

    Methods

    • add a benchmark task to the task map

      Parameters

      • name: string

        the task name

      • fn: Fn

        the task function

      • fnOpts: FnOptions = {}

        the task function options

      Returns this

      the Bench instance

      if the task already exists

      -
    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

      +
    +
    diff --git a/docs/classes/Task.html b/docs/classes/Task.html index d12d8a5..f8ee8fb 100644 --- a/docs/classes/Task.html +++ b/docs/classes/Task.html @@ -1,6 +1,6 @@ Task | tinybench - v5.1.0
    tinybench - v5.1.0
      Preparing search index...

      Class Task

      A class that represents each benchmark task in Tinybench. It keeps track of the results, name, the task function, the number times the task function has been executed, ...

      -

      Hierarchy

      • EventTarget
        • Task
      Index

      Constructors

      Hierarchy

      • EventTarget
        • Task
      Index

      Constructors

      Properties

      Accessors

      name @@ -12,24 +12,24 @@ runSync warmup warmupSync -

      Constructors

      Properties

      addEventListener: <K extends TaskEvents>(
          type: K,
          listener: EventListener<K, "task"> | EventListenerObject<K, "task"> | null,
          options?: boolean | AddEventListenerOptions,
      ) => void

      The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      +

      Constructors

      Properties

      addEventListener: <K extends TaskEvents>(
          type: K,
          listener: EventListener<K, "task"> | EventListenerObject<K, "task"> | null,
          options?: boolean | AddEventListenerOptions,
      ) => void

      The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

      MDN Reference

      -
      removeEventListener: <K extends TaskEvents>(
          type: K,
          listener: EventListener<K, "task"> | EventListenerObject<K, "task"> | null,
          options?: boolean | EventListenerOptions,
      ) => void

      The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

      +
      removeEventListener: <K extends TaskEvents>(
          type: K,
          listener: EventListener<K, "task"> | EventListenerObject<K, "task"> | null,
          options?: boolean | EventListenerOptions,
      ) => void

      The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

      MDN Reference

      -

      Accessors

      • get name(): string

        The name of the task

        +

      Accessors

      • get name(): string

        The name of the task

        Returns string

        the name of the task

        -
      • get runs(): number

        The number of times the task function has been executed

        +
      • get runs(): number

        The number of times the task function has been executed

        Returns number

        the number of times the task function has been executed

        -

      Methods

      • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

        +

      Methods

      • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

        MDN Reference

        Parameters

        • event: Event

        Returns boolean

      • Internal

        reset the task to make the Task.runs a zero-value and remove the Task.result object property

        Parameters

        • emit: boolean = true

          whether to emit the reset event or not

          -

        Returns void

      • Internal

        run the current task and write the results in Task.result object property

        +

      Returns void

      +
      diff --git a/docs/functions/hrtimeNow.html b/docs/functions/hrtimeNow.html index d8f60d4..9572d22 100644 --- a/docs/functions/hrtimeNow.html +++ b/docs/functions/hrtimeNow.html @@ -1,3 +1,3 @@ hrtimeNow | tinybench - v5.1.0
      tinybench - v5.1.0
        Preparing search index...

        Function hrtimeNow

        • Returns the current high resolution timestamp in milliseconds using process.hrtime.bigint().

          Returns number

          the current high resolution timestamp in milliseconds

          -
        +
        diff --git a/docs/functions/nToMs.html b/docs/functions/nToMs.html index 15d52eb..341591f 100644 --- a/docs/functions/nToMs.html +++ b/docs/functions/nToMs.html @@ -1,4 +1,4 @@ nToMs | tinybench - v5.1.0
        tinybench - v5.1.0
          Preparing search index...

          Function nToMs

          • Converts nanoseconds to milliseconds.

            Parameters

            • ns: number

              the nanoseconds to convert

            Returns number

            the milliseconds

            -
          +
          diff --git a/docs/hierarchy.html b/docs/hierarchy.html index e89944b..6c3f78b 100644 --- a/docs/hierarchy.html +++ b/docs/hierarchy.html @@ -1 +1 @@ -tinybench - v5.1.0
          tinybench - v5.1.0
            Preparing search index...

            tinybench - v5.1.0

            Hierarchy Summary

            +tinybench - v5.1.0
            tinybench - v5.1.0
              Preparing search index...

              tinybench - v5.1.0

              Hierarchy Summary

              diff --git a/docs/index.html b/docs/index.html index 3f3407f..46fde02 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1 +1 @@ -tinybench - v5.1.0
              tinybench - v5.1.0
                Preparing search index...

                tinybench - v5.1.0

                Classes

                Bench
                Task

                Interfaces

                BenchEvent
                BenchLike
                BenchOptions
                EventListenerObject
                FnOptions
                FnReturnedObject
                ResolvedBenchOptions
                Statistics
                TaskResultAborted
                TaskResultAbortedWithStatistics
                TaskResultCompleted
                TaskResultErrored
                TaskResultNotStarted
                TaskResultRuntimeInfo
                TaskResultStarted
                TaskResultWithStatistics

                Type Aliases

                BenchEvents
                BenchEventsWithTask
                Concurrency
                ConsoleTableConverter
                EventListener
                Fn
                FnHook
                Hook
                JSRuntime
                NowFn
                TaskEvents
                TaskResult

                Variables

                now

                Functions

                hrtimeNow
                nToMs
                +tinybench - v5.1.0
                tinybench - v5.1.0
                  Preparing search index...

                  tinybench - v5.1.0

                  Classes

                  Bench
                  Task

                  Interfaces

                  BenchEvent
                  BenchLike
                  BenchOptions
                  EventListenerObject
                  FnOptions
                  FnReturnedObject
                  ResolvedBenchOptions
                  Statistics
                  TaskResultAborted
                  TaskResultAbortedWithStatistics
                  TaskResultCompleted
                  TaskResultErrored
                  TaskResultNotStarted
                  TaskResultRuntimeInfo
                  TaskResultStarted
                  TaskResultWithStatistics

                  Type Aliases

                  BenchEvents
                  BenchEventsWithTask
                  Concurrency
                  ConsoleTableConverter
                  EventListener
                  Fn
                  FnHook
                  Hook
                  JSRuntime
                  NowFn
                  Samples
                  SortedSamples
                  TaskEvents
                  TaskResult

                  Variables

                  now

                  Functions

                  hrtimeNow
                  nToMs
                  diff --git a/docs/interfaces/BenchEvent.html b/docs/interfaces/BenchEvent.html index f690777..661caef 100644 --- a/docs/interfaces/BenchEvent.html +++ b/docs/interfaces/BenchEvent.html @@ -1,6 +1,6 @@ BenchEvent | tinybench - v5.1.0
                  tinybench - v5.1.0
                    Preparing search index...

                    Interface BenchEvent<K, M>

                    The BenchEvent class represents events that occur during the benchmarking process.

                    -
                    interface BenchEvent<
                        K extends BenchEvents = BenchEvents,
                        M extends "bench" | "task" = "bench",
                    > {
                        AT_TARGET: 2;
                        bubbles: boolean;
                        BUBBLING_PHASE: 3;
                        cancelable: boolean;
                        cancelBubble: boolean;
                        CAPTURING_PHASE: 1;
                        composed: boolean;
                        currentTarget: EventTarget | null;
                        defaultPrevented: boolean;
                        eventPhase: number;
                        isTrusted: boolean;
                        NONE: 0;
                        returnValue: boolean;
                        srcElement: EventTarget | null;
                        target: EventTarget | null;
                        timeStamp: number;
                        type: K;
                        get error(): K extends "error" ? Error : undefined;
                        get task(): M extends "task"
                            ? Task
                            : K extends BenchEventsWithTask ? Task : undefined;
                        composedPath(): EventTarget[];
                        initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
                        preventDefault(): void;
                        stopImmediatePropagation(): void;
                        stopPropagation(): void;
                    }

                    Type Parameters

                    Hierarchy

                    • Event
                      • BenchEvent
                    Index

                    Properties

                    interface BenchEvent<
                        K extends BenchEvents = BenchEvents,
                        M extends "bench" | "task" = "bench",
                    > {
                        AT_TARGET: 2;
                        bubbles: boolean;
                        BUBBLING_PHASE: 3;
                        cancelable: boolean;
                        cancelBubble: boolean;
                        CAPTURING_PHASE: 1;
                        composed: boolean;
                        currentTarget: EventTarget | null;
                        defaultPrevented: boolean;
                        eventPhase: number;
                        isTrusted: boolean;
                        NONE: 0;
                        returnValue: boolean;
                        srcElement: EventTarget | null;
                        target: EventTarget | null;
                        timeStamp: number;
                        type: K;
                        get error(): K extends "error" ? Error : undefined;
                        get task(): M extends "task"
                            ? Task
                            : K extends BenchEventsWithTask ? Task : undefined;
                        composedPath(): EventTarget[];
                        initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
                        preventDefault(): void;
                        stopImmediatePropagation(): void;
                        stopPropagation(): void;
                    }

                    Type Parameters

                    Hierarchy

                    • Event
                      • BenchEvent
                    Index

                    Properties

                    type: K

                    The type read-only property of the Event interface returns a string containing the event's type.

                    MDN Reference

                    -

                    Accessors

                    • get error(): K extends "error" ? Error : undefined

                      The error associated with the event.

                      +

                    Accessors

                    • get error(): K extends "error" ? Error : undefined

                      The error associated with the event.

                      Returns K extends "error" ? Error : undefined

                      The error if the event type is one that includes an error; otherwise, undefined.

                      -

                    Methods

                    • The composedPath() method of the Event interface returns the event's path which is an array of the objects on which listeners will be invoked.

                      +

                    Methods

                    • The composedPath() method of the Event interface returns the event's path which is an array of the objects on which listeners will be invoked.

                      MDN Reference

                      Returns EventTarget[]

                    • The Event.initEvent() method is used to initialize the value of an event created using Document.createEvent().

                      Parameters

                      • type: string
                      • Optionalbubbles: boolean
                      • Optionalcancelable: boolean

                      Returns void

                      MDN Reference

                      diff --git a/docs/interfaces/BenchLike.html b/docs/interfaces/BenchLike.html index 743a2c1..98e7065 100644 --- a/docs/interfaces/BenchLike.html +++ b/docs/interfaces/BenchLike.html @@ -1,9 +1,10 @@ BenchLike | tinybench - v5.1.0
                      tinybench - v5.1.0
                        Preparing search index...

                        Interface BenchLike

                        Used to decouple Bench and Task

                        -
                        interface BenchLike {
                            addEventListener: <K extends BenchEvents>(
                                type: K,
                                listener:
                                    | EventListener<K, "bench">
                                    | EventListenerObject<K, "bench">
                                    | null,
                                options?: boolean | AddEventListenerOptions,
                            ) => void;
                            concurrency: Concurrency;
                            iterations: number;
                            now: NowFn;
                            removeEventListener: <K extends BenchEvents>(
                                type: K,
                                listener:
                                    | EventListener<K, "bench">
                                    | EventListenerObject<K, "bench">
                                    | null,
                                options?: boolean | EventListenerOptions,
                            ) => void;
                            runtime: JSRuntime;
                            runtimeVersion: string;
                            setup: (task: Task, mode: "warmup" | "run") => void | Promise<void>;
                            signal?: AbortSignal;
                            teardown: (task: Task, mode: "warmup" | "run") => void | Promise<void>;
                            threshold: number;
                            throws: boolean;
                            time: number;
                            warmup: boolean;
                            warmupIterations: number;
                            warmupTime: number;
                            dispatchEvent(event: Event): boolean;
                        }

                        Hierarchy

                        • EventTarget
                          • BenchLike

                        Implemented by

                        Index

                        Properties

                        interface BenchLike {
                            addEventListener: <K extends BenchEvents>(
                                type: K,
                                listener:
                                    | EventListener<K, "bench">
                                    | EventListenerObject<K, "bench">
                                    | null,
                                options?: boolean | AddEventListenerOptions,
                            ) => void;
                            concurrency: Concurrency;
                            iterations: number;
                            now: NowFn;
                            removeEventListener: <K extends BenchEvents>(
                                type: K,
                                listener:
                                    | EventListener<K, "bench">
                                    | EventListenerObject<K, "bench">
                                    | null,
                                options?: boolean | EventListenerOptions,
                            ) => void;
                            retainSamples: boolean;
                            runtime: JSRuntime;
                            runtimeVersion: string;
                            setup: (task: Task, mode: "warmup" | "run") => void | Promise<void>;
                            signal?: AbortSignal;
                            teardown: (task: Task, mode: "warmup" | "run") => void | Promise<void>;
                            threshold: number;
                            throws: boolean;
                            time: number;
                            warmup: boolean;
                            warmupIterations: number;
                            warmupTime: number;
                            dispatchEvent(event: Event): boolean;
                        }

                        Hierarchy

                        • EventTarget
                          • BenchLike

                        Implemented by

                        Index

                        Properties

                        addEventListener: <K extends BenchEvents>(
                            type: K,
                            listener:
                                | EventListener<K, "bench">
                                | EventListenerObject<K, "bench">
                                | null,
                            options?: boolean | AddEventListenerOptions,
                        ) => void

                        Adds a listener for the specified event type.

                        -
                        concurrency: Concurrency

                        Executes tasks concurrently based on the specified concurrency mode, if set.

                        +
                        concurrency: Concurrency

                        Executes tasks concurrently based on the specified concurrency mode, if set.

                        • When mode is set to null (default), concurrency is disabled.
                        • When mode is set to 'task', each task's iterations (calls of a task function) run concurrently.
                        • When mode is set to 'bench', different tasks within the bench run concurrently.
                        -
                        iterations: number

                        The amount of executions per task.

                        -
                        now: NowFn

                        A function to get a timestamp.

                        -
                        removeEventListener: <K extends BenchEvents>(
                            type: K,
                            listener:
                                | EventListener<K, "bench">
                                | EventListenerObject<K, "bench">
                                | null,
                            options?: boolean | EventListenerOptions,
                        ) => void

                        Removes a previously registered event listener.

                        -
                        runtime: JSRuntime

                        The JavaScript runtime environment.

                        -
                        runtimeVersion: string

                        The JavaScript runtime version.

                        -
                        setup: (task: Task, mode: "warmup" | "run") => void | Promise<void>

                        A setup function that runs before each task execution.

                        -
                        signal?: AbortSignal

                        An AbortSignal to cancel the benchmark

                        -
                        teardown: (task: Task, mode: "warmup" | "run") => void | Promise<void>

                        A teardown function that runs after each task execution.

                        -
                        threshold: number

                        The maximum number of concurrent tasks to run

                        -
                        throws: boolean

                        Whether to throw an error if a task function throws

                        -
                        time: number

                        The amount of time to run each task.

                        -
                        warmup: boolean

                        Whether to warmup the tasks before running them

                        -
                        warmupIterations: number

                        The amount of warmup iterations per task.

                        -
                        warmupTime: number

                        The amount of time to warmup each task.

                        -

                        Methods

                        • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

                          +
                        iterations: number

                        The amount of executions per task.

                        +
                        now: NowFn

                        A function to get a timestamp.

                        +
                        removeEventListener: <K extends BenchEvents>(
                            type: K,
                            listener:
                                | EventListener<K, "bench">
                                | EventListenerObject<K, "bench">
                                | null,
                            options?: boolean | EventListenerOptions,
                        ) => void

                        Removes a previously registered event listener.

                        +
                        retainSamples: boolean

                        Should samples be retained for further custom processing

                        +
                        runtime: JSRuntime

                        The JavaScript runtime environment.

                        +
                        runtimeVersion: string

                        The JavaScript runtime version.

                        +
                        setup: (task: Task, mode: "warmup" | "run") => void | Promise<void>

                        A setup function that runs before each task execution.

                        +
                        signal?: AbortSignal

                        An AbortSignal to cancel the benchmark

                        +
                        teardown: (task: Task, mode: "warmup" | "run") => void | Promise<void>

                        A teardown function that runs after each task execution.

                        +
                        threshold: number

                        The maximum number of concurrent tasks to run

                        +
                        throws: boolean

                        Whether to throw an error if a task function throws

                        +
                        time: number

                        The amount of time to run each task.

                        +
                        warmup: boolean

                        Whether to warmup the tasks before running them

                        +
                        warmupIterations: number

                        The amount of warmup iterations per task.

                        +
                        warmupTime: number

                        The amount of time to warmup each task.

                        +

                        Methods

                        • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

                          MDN Reference

                          -

                          Parameters

                          • event: Event

                          Returns boolean

                        +

                        Parameters

                        • event: Event

                        Returns boolean

                      diff --git a/docs/interfaces/BenchOptions.html b/docs/interfaces/BenchOptions.html index 8b6b63e..61153fe 100644 --- a/docs/interfaces/BenchOptions.html +++ b/docs/interfaces/BenchOptions.html @@ -1,8 +1,9 @@ BenchOptions | tinybench - v5.1.0
                      tinybench - v5.1.0
                        Preparing search index...

                        Interface BenchOptions

                        Bench options

                        -
                        interface BenchOptions {
                            concurrency?: Concurrency;
                            iterations?: number;
                            name?: string;
                            now?: NowFn;
                            setup?: Hook;
                            signal?: AbortSignal;
                            teardown?: Hook;
                            threshold?: number;
                            throws?: boolean;
                            time?: number;
                            warmup?: boolean;
                            warmupIterations?: number;
                            warmupTime?: number;
                        }

                        Hierarchy (View Summary)

                        Index

                        Properties

                        interface BenchOptions {
                            concurrency?: Concurrency;
                            iterations?: number;
                            name?: string;
                            now?: NowFn;
                            retainSamples?: boolean;
                            setup?: Hook;
                            signal?: AbortSignal;
                            teardown?: Hook;
                            threshold?: number;
                            throws?: boolean;
                            time?: number;
                            warmup?: boolean;
                            warmupIterations?: number;
                            warmupTime?: number;
                        }

                        Hierarchy (View Summary)

                        Index

                        Properties

                        concurrency? iterations? name? now? +retainSamples? setup? signal? teardown? @@ -18,37 +19,41 @@
                      • When mode is set to 'task', each task's iterations (calls of a task function) run concurrently.
                      • When mode is set to 'bench', different tasks within the bench run concurrently.
                      • -
                        iterations?: number

                        number of times that a task should run if even the time option is finished

                        +
                        iterations?: number

                        number of times that a task should run if even the time option is finished

                        64
                         
                        -
                        name?: string

                        benchmark name

                        -
                        now?: NowFn

                        function to get the current timestamp in milliseconds

                        -
                        setup?: Hook

                        setup function to run before each benchmark task (cycle)

                        -
                        signal?: AbortSignal

                        An AbortSignal for aborting the benchmark

                        -
                        teardown?: Hook

                        teardown function to run after each benchmark task (cycle)

                        -
                        threshold?: number

                        The maximum number of concurrent tasks to run

                        -
                        Infinity
                        +
                        name?: string

                        benchmark name

                        +
                        now?: NowFn

                        function to get the current timestamp in milliseconds

                        +
                        retainSamples?: boolean

                        keep samples for statistics calculation

                        +
                        false
                         
                        -
                        throws?: boolean

                        Throws if a task fails

                        -
                        false
                        +
                        setup?: Hook

                        setup function to run before each benchmark task (cycle)

                        +
                        signal?: AbortSignal

                        An AbortSignal for aborting the benchmark

                        +
                        teardown?: Hook

                        teardown function to run after each benchmark task (cycle)

                        +
                        threshold?: number

                        The maximum number of concurrent tasks to run

                        +
                        Infinity
                         
                        -
                        time?: number

                        time needed for running a benchmark task (milliseconds)

                        -
                        1000
                        +
                        throws?: boolean

                        Throws if a task fails

                        +
                        false
                         
                        -
                        warmup?: boolean

                        warmup benchmark

                        -
                        true
                        +
                        time?: number

                        time needed for running a benchmark task (milliseconds)

                        +
                        1000
                         
                        -
                        warmupIterations?: number

                        warmup iterations

                        -
                        16
                        +
                        warmup?: boolean

                        warmup benchmark

                        +
                        true
                         
                        -
                        warmupTime?: number

                        warmup time (milliseconds)

                        -
                        250
                        +
                        warmupIterations?: number

                        warmup iterations

                        +
                        16
                         
                        -
                        +
                        warmupTime?: number

                        warmup time (milliseconds)

                        +
                        250
                        +
                        + +
                        diff --git a/docs/interfaces/EventListenerObject.html b/docs/interfaces/EventListenerObject.html index 0c5b5df..2c77f2d 100644 --- a/docs/interfaces/EventListenerObject.html +++ b/docs/interfaces/EventListenerObject.html @@ -1,6 +1,6 @@ EventListenerObject | tinybench - v5.1.0
                        tinybench - v5.1.0
                          Preparing search index...

                          Interface EventListenerObject<E, M>

                          Both the Task and Bench objects extend the EventTarget object. So you can attach a listeners to different types of events to each class instance using the universal addEventListener and removeEventListener methods.

                          -
                          interface EventListenerObject<
                              E extends BenchEvents,
                              M extends "bench" | "task" = "bench",
                          > {
                              handleEvent(evt: BenchEvent<E, M>): void;
                          }

                          Type Parameters

                          • E extends BenchEvents
                          • M extends "bench" | "task" = "bench"
                          Index

                          Methods

                          interface EventListenerObject<
                              E extends BenchEvents,
                              M extends "bench" | "task" = "bench",
                          > {
                              handleEvent(evt: BenchEvent<E, M>): void;
                          }

                          Type Parameters

                          • E extends BenchEvents
                          • M extends "bench" | "task" = "bench"
                          Index

                          Methods

                          Methods

                          +

                          Parameters

                          Returns void

                          diff --git a/docs/interfaces/FnOptions.html b/docs/interfaces/FnOptions.html index bf7c560..f5e2911 100644 --- a/docs/interfaces/FnOptions.html +++ b/docs/interfaces/FnOptions.html @@ -1,16 +1,18 @@ FnOptions | tinybench - v5.1.0
                          tinybench - v5.1.0
                            Preparing search index...

                            Interface FnOptions

                            The task function options

                            -
                            interface FnOptions {
                                afterAll?: FnHook;
                                afterEach?: FnHook;
                                async?: boolean;
                                beforeAll?: FnHook;
                                beforeEach?: FnHook;
                                signal?: AbortSignal;
                            }
                            Index

                            Properties

                            interface FnOptions {
                                afterAll?: FnHook;
                                afterEach?: FnHook;
                                async?: boolean;
                                beforeAll?: FnHook;
                                beforeEach?: FnHook;
                                retainSamples?: boolean;
                                signal?: AbortSignal;
                            }
                            Index

                            Properties

                            afterAll?: FnHook

                            An optional function that is run after all iterations of this task end

                            -
                            afterEach?: FnHook

                            An optional function that is run after each iteration of this task

                            -
                            async?: boolean

                            Whether the provided task function is asynchronous, otherwise it is +

                            afterEach?: FnHook

                            An optional function that is run after each iteration of this task

                            +
                            async?: boolean

                            Whether the provided task function is asynchronous, otherwise it is determined automatically.

                            -
                            beforeAll?: FnHook

                            An optional function that is run before iterations of this task begin

                            -
                            beforeEach?: FnHook

                            An optional function that is run before each iteration of this task

                            -
                            signal?: AbortSignal

                            An AbortSignal for aborting this specific task

                            +
                            beforeAll?: FnHook

                            An optional function that is run before iterations of this task begin

                            +
                            beforeEach?: FnHook

                            An optional function that is run before each iteration of this task

                            +
                            retainSamples?: boolean

                            Retain samples for this task, overriding the bench-level retainSamples option

                            +
                            signal?: AbortSignal

                            An AbortSignal for aborting this specific task

                            If not provided, falls back to BenchOptions.signal

                            -
                            +
                            diff --git a/docs/interfaces/FnReturnedObject.html b/docs/interfaces/FnReturnedObject.html index f7ea5bd..5b0ea7e 100644 --- a/docs/interfaces/FnReturnedObject.html +++ b/docs/interfaces/FnReturnedObject.html @@ -1,8 +1,8 @@ FnReturnedObject | tinybench - v5.1.0
                            tinybench - v5.1.0
                              Preparing search index...

                              Interface FnReturnedObject

                              A possible object returned by task functions to override default behaviors, like the duration of the function itself.

                              -
                              interface FnReturnedObject {
                                  overriddenDuration?: number;
                              }
                              Index

                              Properties

                              interface FnReturnedObject {
                                  overriddenDuration?: number;
                              }
                              Index

                              Properties

                              overriddenDuration?: number

                              An overridden duration for the task function, to be used instead of the duration measured by tinybench when running the benchmark.

                              This can be useful to measure parts of the execution of a function that are hard to execute independently.

                              -
                              +
                              diff --git a/docs/interfaces/ResolvedBenchOptions.html b/docs/interfaces/ResolvedBenchOptions.html index 38a3e06..64ce515 100644 --- a/docs/interfaces/ResolvedBenchOptions.html +++ b/docs/interfaces/ResolvedBenchOptions.html @@ -1,8 +1,9 @@ ResolvedBenchOptions | tinybench - v5.1.0
                              tinybench - v5.1.0
                                Preparing search index...

                                Interface ResolvedBenchOptions

                                The resolved benchmark options

                                -
                                interface ResolvedBenchOptions {
                                    concurrency?: Concurrency;
                                    iterations: number;
                                    name?: string;
                                    now: NowFn;
                                    setup: Hook;
                                    signal?: AbortSignal;
                                    teardown: Hook;
                                    threshold?: number;
                                    throws: NonNullable<boolean | undefined>;
                                    time: number;
                                    warmup: NonNullable<boolean | undefined>;
                                    warmupIterations: number;
                                    warmupTime: number;
                                }

                                Hierarchy (View Summary)

                                Index

                                Properties

                                interface ResolvedBenchOptions {
                                    concurrency?: Concurrency;
                                    iterations: number;
                                    name?: string;
                                    now: NowFn;
                                    retainSamples?: boolean;
                                    setup: Hook;
                                    signal?: AbortSignal;
                                    teardown: Hook;
                                    threshold?: number;
                                    throws: NonNullable<boolean | undefined>;
                                    time: number;
                                    warmup: NonNullable<boolean | undefined>;
                                    warmupIterations: number;
                                    warmupTime: number;
                                }

                                Hierarchy (View Summary)

                                Index

                                Properties

                                concurrency? iterations name? now +retainSamples? setup signal? teardown @@ -18,37 +19,41 @@
                              • When mode is set to 'task', each task's iterations (calls of a task function) run concurrently.
                              • When mode is set to 'bench', different tasks within the bench run concurrently.
                              • -
                                iterations: number

                                number of times that a task should run if even the time option is finished

                                +
                                iterations: number

                                number of times that a task should run if even the time option is finished

                                64
                                 
                                -
                                name?: string

                                benchmark name

                                -
                                now: NowFn

                                function to get the current timestamp in milliseconds

                                -
                                setup: Hook

                                setup function to run before each benchmark task (cycle)

                                -
                                signal?: AbortSignal

                                An AbortSignal for aborting the benchmark

                                -
                                teardown: Hook

                                teardown function to run after each benchmark task (cycle)

                                -
                                threshold?: number

                                The maximum number of concurrent tasks to run

                                -
                                Infinity
                                +
                                name?: string

                                benchmark name

                                +
                                now: NowFn

                                function to get the current timestamp in milliseconds

                                +
                                retainSamples?: boolean

                                keep samples for statistics calculation

                                +
                                false
                                 
                                -
                                throws: NonNullable<boolean | undefined>

                                Throws if a task fails

                                -
                                false
                                +
                                setup: Hook

                                setup function to run before each benchmark task (cycle)

                                +
                                signal?: AbortSignal

                                An AbortSignal for aborting the benchmark

                                +
                                teardown: Hook

                                teardown function to run after each benchmark task (cycle)

                                +
                                threshold?: number

                                The maximum number of concurrent tasks to run

                                +
                                Infinity
                                 
                                -
                                time: number

                                time needed for running a benchmark task (milliseconds)

                                -
                                1000
                                +
                                throws: NonNullable<boolean | undefined>

                                Throws if a task fails

                                +
                                false
                                 
                                -
                                warmup: NonNullable<boolean | undefined>

                                warmup benchmark

                                -
                                true
                                +
                                time: number

                                time needed for running a benchmark task (milliseconds)

                                +
                                1000
                                 
                                -
                                warmupIterations: number

                                warmup iterations

                                -
                                16
                                +
                                warmup: NonNullable<boolean | undefined>

                                warmup benchmark

                                +
                                true
                                 
                                -
                                warmupTime: number

                                warmup time (milliseconds)

                                -
                                250
                                +
                                warmupIterations: number

                                warmup iterations

                                +
                                16
                                 
                                -
                                +
                                warmupTime: number

                                warmup time (milliseconds)

                                +
                                250
                                +
                                + +
                                diff --git a/docs/interfaces/Statistics.html b/docs/interfaces/Statistics.html index f1049ff..40015c3 100644 --- a/docs/interfaces/Statistics.html +++ b/docs/interfaces/Statistics.html @@ -1,5 +1,5 @@ Statistics | tinybench - v5.1.0
                                tinybench - v5.1.0
                                  Preparing search index...

                                  Interface Statistics

                                  The statistics object

                                  -
                                  interface Statistics {
                                      aad: number;
                                      critical: number;
                                      df: number;
                                      mad: number;
                                      max: number;
                                      mean: number;
                                      min: number;
                                      moe: number;
                                      p50: number;
                                      p75: number;
                                      p99: number;
                                      p995: number;
                                      p999: number;
                                      rme: number;
                                      samples: number[];
                                      sd: number;
                                      sem: number;
                                      variance: number;
                                  }
                                  Index

                                  Properties

                                  aad +
                                  interface Statistics {
                                      aad: number;
                                      critical: number;
                                      df: number;
                                      mad: number;
                                      max: number;
                                      mean: number;
                                      min: number;
                                      moe: number;
                                      p50: number;
                                      p75: number;
                                      p99: number;
                                      p995: number;
                                      p999: number;
                                      rme: number;
                                      samples: SortedSamples | undefined;
                                      samplesCount: number;
                                      sd: number;
                                      sem: number;
                                      variance: number;
                                  }
                                  Index

                                  Properties

                                  Properties

                                  aad: number

                                  mean/average absolute deviation

                                  -
                                  critical: number

                                  critical value

                                  -
                                  df: number

                                  degrees of freedom

                                  -
                                  mad: number

                                  median absolute deviation

                                  -
                                  max: number

                                  the maximum value

                                  -
                                  mean: number

                                  mean/average

                                  -
                                  min: number

                                  the minimum value

                                  -
                                  moe: number

                                  margin of error

                                  -
                                  p50: number

                                  p50/median percentile

                                  -
                                  p75: number

                                  p75 percentile

                                  -
                                  p99: number

                                  p99 percentile

                                  -
                                  p995: number

                                  p995 percentile

                                  -
                                  p999: number

                                  p999 percentile

                                  -
                                  rme: number

                                  relative margin of error

                                  -
                                  samples: number[]

                                  samples

                                  -
                                  sd: number

                                  standard deviation

                                  -
                                  sem: number

                                  standard error of the mean/average (a.k.a. the standard deviation of the distribution of the sample mean/average)

                                  -
                                  variance: number

                                  variance

                                  -
                                  +
                                  critical: number

                                  critical value

                                  +
                                  df: number

                                  degrees of freedom

                                  +
                                  mad: number

                                  median absolute deviation

                                  +
                                  max: number

                                  the maximum value

                                  +
                                  mean: number

                                  mean/average

                                  +
                                  min: number

                                  the minimum value

                                  +
                                  moe: number

                                  margin of error

                                  +
                                  p50: number

                                  p50/median percentile

                                  +
                                  p75: number

                                  p75 percentile

                                  +
                                  p99: number

                                  p99 percentile

                                  +
                                  p995: number

                                  p995 percentile

                                  +
                                  p999: number

                                  p999 percentile

                                  +
                                  rme: number

                                  relative margin of error

                                  +
                                  samples: SortedSamples | undefined

                                  samples used to calculate the statistics

                                  +
                                  samplesCount: number

                                  samples count

                                  +
                                  sd: number

                                  standard deviation

                                  +
                                  sem: number

                                  standard error of the mean/average (a.k.a. the standard deviation of the distribution of the sample mean/average)

                                  +
                                  variance: number

                                  variance

                                  +
                                  diff --git a/docs/interfaces/TaskResultAborted.html b/docs/interfaces/TaskResultAborted.html index e552f96..6408ac5 100644 --- a/docs/interfaces/TaskResultAborted.html +++ b/docs/interfaces/TaskResultAborted.html @@ -1,4 +1,4 @@ TaskResultAborted | tinybench - v5.1.0
                                  tinybench - v5.1.0
                                    Preparing search index...

                                    Interface TaskResultAborted

                                    The task result for aborted tasks.

                                    -
                                    interface TaskResultAborted {
                                        state: "aborted";
                                    }
                                    Index

                                    Properties

                                    interface TaskResultAborted {
                                        state: "aborted";
                                    }
                                    Index

                                    Properties

                                    Properties

                                    state: "aborted"

                                    the task state

                                    -
                                    +
                                    diff --git a/docs/interfaces/TaskResultAbortedWithStatistics.html b/docs/interfaces/TaskResultAbortedWithStatistics.html index 53d3eda..fe40f91 100644 --- a/docs/interfaces/TaskResultAbortedWithStatistics.html +++ b/docs/interfaces/TaskResultAbortedWithStatistics.html @@ -1,12 +1,12 @@ TaskResultAbortedWithStatistics | tinybench - v5.1.0
                                    tinybench - v5.1.0
                                      Preparing search index...

                                      Interface TaskResultAbortedWithStatistics

                                      The task result for aborted tasks, having also statistical data.

                                      -
                                      interface TaskResultAbortedWithStatistics {
                                          latency: Statistics;
                                          period: number;
                                          state: "aborted-with-statistics";
                                          throughput: Statistics;
                                          totalTime: number;
                                      }

                                      Hierarchy (View Summary)

                                      Index

                                      Properties

                                      interface TaskResultAbortedWithStatistics {
                                          latency: Statistics;
                                          period: number;
                                          state: "aborted-with-statistics";
                                          throughput: Statistics;
                                          totalTime: number;
                                      }

                                      Hierarchy (View Summary)

                                      Index

                                      Properties

                                      latency: Statistics

                                      the task latency statistics

                                      -
                                      period: number

                                      how long each operation takes (ms)

                                      -
                                      state: "aborted-with-statistics"

                                      the task state

                                      -
                                      throughput: Statistics

                                      the task throughput statistics

                                      -
                                      totalTime: number

                                      the time to run the task benchmark cycle (ms)

                                      -
                                      +
                                      period: number

                                      how long each operation takes (ms)

                                      +
                                      state: "aborted-with-statistics"

                                      the task state

                                      +
                                      throughput: Statistics

                                      the task throughput statistics

                                      +
                                      totalTime: number

                                      the time to run the task benchmark cycle (ms)

                                      +
                                      diff --git a/docs/interfaces/TaskResultCompleted.html b/docs/interfaces/TaskResultCompleted.html index 4bffc87..b284471 100644 --- a/docs/interfaces/TaskResultCompleted.html +++ b/docs/interfaces/TaskResultCompleted.html @@ -1,12 +1,12 @@ TaskResultCompleted | tinybench - v5.1.0
                                      tinybench - v5.1.0
                                        Preparing search index...

                                        Interface TaskResultCompleted

                                        The task result for completed tasks with statistical data.

                                        -
                                        interface TaskResultCompleted {
                                            latency: Statistics;
                                            period: number;
                                            state: "completed";
                                            throughput: Statistics;
                                            totalTime: number;
                                        }

                                        Hierarchy (View Summary)

                                        Index

                                        Properties

                                        interface TaskResultCompleted {
                                            latency: Statistics;
                                            period: number;
                                            state: "completed";
                                            throughput: Statistics;
                                            totalTime: number;
                                        }

                                        Hierarchy (View Summary)

                                        Index

                                        Properties

                                        latency: Statistics

                                        the task latency statistics

                                        -
                                        period: number

                                        how long each operation takes (ms)

                                        -
                                        state: "completed"

                                        the task state

                                        -
                                        throughput: Statistics

                                        the task throughput statistics

                                        -
                                        totalTime: number

                                        the time to run the task benchmark cycle (ms)

                                        -
                                        +
                                        period: number

                                        how long each operation takes (ms)

                                        +
                                        state: "completed"

                                        the task state

                                        +
                                        throughput: Statistics

                                        the task throughput statistics

                                        +
                                        totalTime: number

                                        the time to run the task benchmark cycle (ms)

                                        +
                                        diff --git a/docs/interfaces/TaskResultErrored.html b/docs/interfaces/TaskResultErrored.html index 9f95e7a..35eb6e9 100644 --- a/docs/interfaces/TaskResultErrored.html +++ b/docs/interfaces/TaskResultErrored.html @@ -1,6 +1,6 @@ TaskResultErrored | tinybench - v5.1.0
                                        tinybench - v5.1.0
                                          Preparing search index...

                                          Interface TaskResultErrored

                                          The task result for errored tasks

                                          -
                                          interface TaskResultErrored {
                                              error: Error;
                                              state: "errored";
                                          }
                                          Index

                                          Properties

                                          interface TaskResultErrored {
                                              error: Error;
                                              state: "errored";
                                          }
                                          Index

                                          Properties

                                          Properties

                                          error: Error

                                          the error that caused the task to fail

                                          -
                                          state: "errored"

                                          the task state

                                          -
                                          +
                                          state: "errored"

                                          the task state

                                          +
                                          diff --git a/docs/interfaces/TaskResultNotStarted.html b/docs/interfaces/TaskResultNotStarted.html index 508e095..ac093bb 100644 --- a/docs/interfaces/TaskResultNotStarted.html +++ b/docs/interfaces/TaskResultNotStarted.html @@ -1,4 +1,4 @@ TaskResultNotStarted | tinybench - v5.1.0
                                          tinybench - v5.1.0
                                            Preparing search index...

                                            Interface TaskResultNotStarted

                                            The task result for not started tasks

                                            -
                                            interface TaskResultNotStarted {
                                                state: "not-started";
                                            }
                                            Index

                                            Properties

                                            interface TaskResultNotStarted {
                                                state: "not-started";
                                            }
                                            Index

                                            Properties

                                            Properties

                                            state: "not-started"

                                            the task state

                                            -
                                            +
                                            diff --git a/docs/interfaces/TaskResultRuntimeInfo.html b/docs/interfaces/TaskResultRuntimeInfo.html index d8a7b5c..9be64c0 100644 --- a/docs/interfaces/TaskResultRuntimeInfo.html +++ b/docs/interfaces/TaskResultRuntimeInfo.html @@ -1,6 +1,6 @@ TaskResultRuntimeInfo | tinybench - v5.1.0
                                            tinybench - v5.1.0
                                              Preparing search index...

                                              Interface TaskResultRuntimeInfo

                                              The additional runtime information for task results

                                              -
                                              interface TaskResultRuntimeInfo {
                                                  runtime: JSRuntime;
                                                  runtimeVersion: string;
                                              }
                                              Index

                                              Properties

                                              interface TaskResultRuntimeInfo {
                                                  runtime: JSRuntime;
                                                  runtimeVersion: string;
                                              }
                                              Index

                                              Properties

                                              runtime: JSRuntime

                                              the JavaScript runtime environment

                                              -
                                              runtimeVersion: string

                                              the JavaScript runtime version

                                              -
                                              +
                                              runtimeVersion: string

                                              the JavaScript runtime version

                                              +
                                              diff --git a/docs/interfaces/TaskResultStarted.html b/docs/interfaces/TaskResultStarted.html index 125e9a4..0fe278f 100644 --- a/docs/interfaces/TaskResultStarted.html +++ b/docs/interfaces/TaskResultStarted.html @@ -1,4 +1,4 @@ TaskResultStarted | tinybench - v5.1.0
                                              tinybench - v5.1.0
                                                Preparing search index...

                                                Interface TaskResultStarted

                                                The task result for started tasks

                                                -
                                                interface TaskResultStarted {
                                                    state: "started";
                                                }
                                                Index

                                                Properties

                                                interface TaskResultStarted {
                                                    state: "started";
                                                }
                                                Index

                                                Properties

                                                Properties

                                                state: "started"

                                                the task state

                                                -
                                                +
                                                diff --git a/docs/interfaces/TaskResultWithStatistics.html b/docs/interfaces/TaskResultWithStatistics.html index 3240b73..c469089 100644 --- a/docs/interfaces/TaskResultWithStatistics.html +++ b/docs/interfaces/TaskResultWithStatistics.html @@ -1,10 +1,10 @@ TaskResultWithStatistics | tinybench - v5.1.0
                                                tinybench - v5.1.0
                                                  Preparing search index...

                                                  Interface TaskResultWithStatistics

                                                  The statistical data for task results

                                                  -
                                                  interface TaskResultWithStatistics {
                                                      latency: Statistics;
                                                      period: number;
                                                      throughput: Statistics;
                                                      totalTime: number;
                                                  }

                                                  Hierarchy (View Summary)

                                                  Index

                                                  Properties

                                                  interface TaskResultWithStatistics {
                                                      latency: Statistics;
                                                      period: number;
                                                      throughput: Statistics;
                                                      totalTime: number;
                                                  }

                                                  Hierarchy (View Summary)

                                                  Index

                                                  Properties

                                                  latency: Statistics

                                                  the task latency statistics

                                                  -
                                                  period: number

                                                  how long each operation takes (ms)

                                                  -
                                                  throughput: Statistics

                                                  the task throughput statistics

                                                  -
                                                  totalTime: number

                                                  the time to run the task benchmark cycle (ms)

                                                  -
                                                  +
                                                  period: number

                                                  how long each operation takes (ms)

                                                  +
                                                  throughput: Statistics

                                                  the task throughput statistics

                                                  +
                                                  totalTime: number

                                                  the time to run the task benchmark cycle (ms)

                                                  +
                                                  diff --git a/docs/types/BenchEvents.html b/docs/types/BenchEvents.html index c929193..60061d2 100644 --- a/docs/types/BenchEvents.html +++ b/docs/types/BenchEvents.html @@ -1,2 +1,2 @@ BenchEvents | tinybench - v5.1.0
                                                  tinybench - v5.1.0
                                                    Preparing search index...

                                                    Type Alias BenchEvents

                                                    BenchEvents:
                                                        | "abort"
                                                        | "add"
                                                        | "complete"
                                                        | "cycle"
                                                        | "error"
                                                        | "remove"
                                                        | "reset"
                                                        | "start"
                                                        | "warmup"

                                                    Bench events

                                                    -
                                                    +
                                                    diff --git a/docs/types/BenchEventsWithTask.html b/docs/types/BenchEventsWithTask.html index 38e74d1..335ea5b 100644 --- a/docs/types/BenchEventsWithTask.html +++ b/docs/types/BenchEventsWithTask.html @@ -1,2 +1,2 @@ BenchEventsWithTask | tinybench - v5.1.0
                                                    tinybench - v5.1.0
                                                      Preparing search index...

                                                      Type Alias BenchEventsWithTask

                                                      BenchEventsWithTask: Extract<BenchEvents, "add" | "cycle" | "error" | "remove">

                                                      Bench events that have an associated Task

                                                      -
                                                      +
                                                      diff --git a/docs/types/Concurrency.html b/docs/types/Concurrency.html index e5dee8b..4884b73 100644 --- a/docs/types/Concurrency.html +++ b/docs/types/Concurrency.html @@ -3,4 +3,4 @@
                                                    • When mode is set to 'task', each task's iterations (calls of a task function) run concurrently.
                                                    • When mode is set to 'bench', different tasks within the bench run concurrently.
                                                    • -
                                                      +
                                                      diff --git a/docs/types/ConsoleTableConverter.html b/docs/types/ConsoleTableConverter.html index 8b20033..1255c11 100644 --- a/docs/types/ConsoleTableConverter.html +++ b/docs/types/ConsoleTableConverter.html @@ -1,2 +1,2 @@ ConsoleTableConverter | tinybench - v5.1.0
                                                      tinybench - v5.1.0
                                                        Preparing search index...

                                                        Type Alias ConsoleTableConverter

                                                        ConsoleTableConverter: (task: Task) => Record<string, number | string>

                                                        Converts a Task to a console.table friendly object

                                                        -

                                                        Type Declaration

                                                          • (task: Task): Record<string, number | string>
                                                          • Parameters

                                                            Returns Record<string, number | string>

                                                        +

                                                        Type Declaration

                                                          • (task: Task): Record<string, number | string>
                                                          • Parameters

                                                            Returns Record<string, number | string>

                                                        diff --git a/docs/types/EventListener.html b/docs/types/EventListener.html index 25e22e3..57d512f 100644 --- a/docs/types/EventListener.html +++ b/docs/types/EventListener.html @@ -1,2 +1,2 @@ EventListener | tinybench - v5.1.0
                                                        tinybench - v5.1.0
                                                          Preparing search index...

                                                          Type Alias EventListener<E, M>

                                                          EventListener: (evt: BenchEvent<E, M>) => void

                                                          Event listener

                                                          -

                                                          Type Parameters

                                                          • E extends BenchEvents
                                                          • M extends "bench" | "task" = "bench"

                                                          Type Declaration

                                                          +

                                                          Type Parameters

                                                          • E extends BenchEvents
                                                          • M extends "bench" | "task" = "bench"

                                                          Type Declaration

                                                          diff --git a/docs/types/Fn.html b/docs/types/Fn.html index 7703837..0f7bbca 100644 --- a/docs/types/Fn.html +++ b/docs/types/Fn.html @@ -3,4 +3,4 @@ you want to measure a specific part of its execution), you can return an object with a overriddenDuration field. You should still use bench.opts.now() to measure that duration.

                                                          -

                                                          Type Declaration

                                                          +

                                                          Type Declaration

                                                          diff --git a/docs/types/FnHook.html b/docs/types/FnHook.html index 97a83b8..fdbfffe 100644 --- a/docs/types/FnHook.html +++ b/docs/types/FnHook.html @@ -1,4 +1,4 @@ FnHook | tinybench - v5.1.0
                                                          tinybench - v5.1.0
                                                            Preparing search index...

                                                            Type Alias FnHook

                                                            FnHook: (this: Task, mode?: "run" | "warmup") => Promise<void> | void

                                                            The task hook function signature. If warmup is enabled, the hook will be called twice, once for the warmup and once for the run.

                                                            Type Declaration

                                                              • (this: Task, mode?: "run" | "warmup"): Promise<void> | void
                                                              • Parameters

                                                                • this: Task
                                                                • Optionalmode: "run" | "warmup"

                                                                  the mode where the hook is being called

                                                                  -

                                                                Returns Promise<void> | void

                                                            +

                                                            Returns Promise<void> | void

                                                            diff --git a/docs/types/Hook.html b/docs/types/Hook.html index b099721..ea2edb5 100644 --- a/docs/types/Hook.html +++ b/docs/types/Hook.html @@ -2,4 +2,4 @@ If warmup is enabled, the hook will be called twice, once for the warmup and once for the run.

                                                            Type Declaration

                                                              • (task?: Task, mode?: "run" | "warmup"): Promise<void> | void
                                                              • Parameters

                                                                • Optionaltask: Task

                                                                  the task instance

                                                                • Optionalmode: "run" | "warmup"

                                                                  the mode where the hook is being called

                                                                  -

                                                                Returns Promise<void> | void

                                                            +

                                                            Returns Promise<void> | void

                                                            diff --git a/docs/types/JSRuntime.html b/docs/types/JSRuntime.html index 11f5339..17f106c 100644 --- a/docs/types/JSRuntime.html +++ b/docs/types/JSRuntime.html @@ -1,3 +1,3 @@ JSRuntime | tinybench - v5.1.0
                                                            tinybench - v5.1.0
                                                              Preparing search index...

                                                              Type Alias JSRuntime

                                                              JSRuntime:
                                                                  | "browser"
                                                                  | "bun"
                                                                  | "deno"
                                                                  | "edge-light"
                                                                  | "fastly"
                                                                  | "hermes"
                                                                  | "jsc"
                                                                  | "lagon"
                                                                  | "moddable"
                                                                  | "netlify"
                                                                  | "node"
                                                                  | "quickjs-ng"
                                                                  | "spidermonkey"
                                                                  | "unknown"
                                                                  | "v8"
                                                                  | "workerd"

                                                              The JavaScript runtime environment.

                                                              +
                                                              diff --git a/docs/types/NowFn.html b/docs/types/NowFn.html index a3a5309..5afcbde 100644 --- a/docs/types/NowFn.html +++ b/docs/types/NowFn.html @@ -1,2 +1,2 @@ NowFn | tinybench - v5.1.0
                                                              tinybench - v5.1.0
                                                                Preparing search index...

                                                                Type Alias NowFn

                                                                NowFn: () => number

                                                                A function that returns the current timestamp.

                                                                -

                                                                Type Declaration

                                                                  • (): number
                                                                  • Returns number

                                                                +

                                                                Type Declaration

                                                                  • (): number
                                                                  • Returns number

                                                                diff --git a/docs/types/Samples.html b/docs/types/Samples.html new file mode 100644 index 0000000..7f481cb --- /dev/null +++ b/docs/types/Samples.html @@ -0,0 +1,2 @@ +Samples | tinybench - v5.1.0
                                                                tinybench - v5.1.0
                                                                  Preparing search index...

                                                                  Type Alias Samples

                                                                  Samples: [number, ...number[]]

                                                                  A type representing a samples-array with at least one number.

                                                                  +
                                                                  diff --git a/docs/types/SortedSamples.html b/docs/types/SortedSamples.html new file mode 100644 index 0000000..4d5b114 --- /dev/null +++ b/docs/types/SortedSamples.html @@ -0,0 +1,3 @@ +SortedSamples | tinybench - v5.1.0
                                                                  tinybench - v5.1.0
                                                                    Preparing search index...

                                                                    Type Alias SortedSamples

                                                                    SortedSamples: Samples & { __sorted__: unique symbol }

                                                                    A type representing a sorted samples-array with at least one number.

                                                                    +

                                                                    Type Declaration

                                                                    • Readonly__sorted__: unique symbol

                                                                      A unique symbol to identify sorted samples

                                                                      +
                                                                    diff --git a/docs/types/TaskEvents.html b/docs/types/TaskEvents.html index d5514a1..c084dbb 100644 --- a/docs/types/TaskEvents.html +++ b/docs/types/TaskEvents.html @@ -1,2 +1,2 @@ TaskEvents | tinybench - v5.1.0
                                                                    tinybench - v5.1.0
                                                                      Preparing search index...

                                                                      Type Alias TaskEvents

                                                                      TaskEvents: Extract<
                                                                          BenchEvents,
                                                                          "abort"
                                                                          | "complete"
                                                                          | "cycle"
                                                                          | "error"
                                                                          | "reset"
                                                                          | "start"
                                                                          | "warmup",
                                                                      >

                                                                      Task events

                                                                      -
                                                                      +
                                                                      diff --git a/docs/types/TaskResult.html b/docs/types/TaskResult.html index d024050..204a610 100644 --- a/docs/types/TaskResult.html +++ b/docs/types/TaskResult.html @@ -1,2 +1,2 @@ TaskResult | tinybench - v5.1.0
                                                                      tinybench - v5.1.0
                                                                        Preparing search index...

                                                                        Type Alias TaskResult

                                                                        The task result

                                                                        -
                                                                        +
                                                                        diff --git a/docs/variables/now.html b/docs/variables/now.html index 64ed00c..6532898 100644 --- a/docs/variables/now.html +++ b/docs/variables/now.html @@ -1,4 +1,4 @@ now | tinybench - v5.1.0
                                                                        tinybench - v5.1.0
                                                                          Preparing search index...

                                                                          Variable nowConst

                                                                          now: () => number = ...

                                                                          Returns the current high resolution timestamp in milliseconds using performance.now().

                                                                          Type Declaration

                                                                            • (): number
                                                                            • The performance.now() method returns a high resolution timestamp in milliseconds.

                                                                              MDN Reference

                                                                              -

                                                                              Returns number

                                                                          +

                                                                          Returns number

                                                                          diff --git a/src/bench.ts b/src/bench.ts index 949457e..943b8ef 100644 --- a/src/bench.ts +++ b/src/bench.ts @@ -72,6 +72,8 @@ export class Bench extends EventTarget implements BenchLike { options?: RemoveEventListenerOptionsArgument ) => void + readonly retainSamples: boolean + /** * The JavaScript runtime environment. */ @@ -173,6 +175,7 @@ export class Bench extends EventTarget implements BenchLike { this.teardown = restOptions.teardown ?? emptyFunction this.throws = restOptions.throws ?? false this.signal = restOptions.signal + this.retainSamples = restOptions.retainSamples === true if (this.signal) { this.signal.addEventListener( diff --git a/src/index.ts b/src/index.ts index 76cb901..e819a4b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,8 @@ export type { JSRuntime, NowFn, ResolvedBenchOptions, + Samples, + SortedSamples, Statistics, TaskEvents, TaskResult, diff --git a/src/task.ts b/src/task.ts index 7783f38..5bd1da8 100644 --- a/src/task.ts +++ b/src/task.ts @@ -6,6 +6,7 @@ import type { Fn, FnOptions, RemoveEventListenerOptionsArgument, + Samples, TaskEvents, TaskResult, TaskResultRuntimeInfo, @@ -18,7 +19,6 @@ import { isFnAsyncResource, isPromiseLike, isValidSamples, - type Samples, sortSamples, toError, withConcurrency, @@ -129,6 +129,11 @@ export class Task extends EventTarget { */ #result: TaskResult = notStartedTaskResult + /** + * Retain samples + */ + readonly #retainSamples: boolean + /** * The number of times the task function has been executed */ @@ -147,6 +152,7 @@ export class Task extends EventTarget { this.#fnOpts = fnOpts this.#async = fnOpts.async ?? isFnAsyncResource(fn) this.#signal = fnOpts.signal + this.#retainSamples = fnOpts.retainSamples ?? bench.retainSamples for (const hookName of hookNames) { if (this.#fnOpts[hookName] != null) { @@ -561,11 +567,11 @@ export class Task extends EventTarget { sortSamples(latencySamples) - const latencyStatistics = getStatisticsSorted(latencySamples) + const latencyStatistics = getStatisticsSorted(latencySamples, this.#retainSamples) const latencyStatisticsMean = latencyStatistics.mean let totalTime = 0 - const throughputSamples = [] as unknown as Samples + const throughputSamples: Samples | undefined = [] as unknown as Samples for (const sample of latencySamples) { if (sample !== 0) { @@ -579,7 +585,7 @@ export class Task extends EventTarget { } sortSamples(throughputSamples) - const throughputStatistics = getStatisticsSorted(throughputSamples) + const throughputStatistics = getStatisticsSorted(throughputSamples, this.#retainSamples) /* eslint-disable perfectionist/sort-objects */ this.#result = { diff --git a/src/types.ts b/src/types.ts index c031dd8..7e2f888 100644 --- a/src/types.ts +++ b/src/types.ts @@ -81,6 +81,11 @@ export interface BenchLike extends EventTarget { options?: RemoveEventListenerOptionsArgument ) => void + /** + * Should samples be retained for further custom processing + */ + retainSamples: boolean + /** * The JavaScript runtime environment. */ @@ -158,7 +163,13 @@ export interface BenchOptions { now?: NowFn /** - * Setup function to run before each benchmark task (cycle). + * Keep samples for statistics calculation + * @default false + */ + retainSamples?: boolean + + /** + * Setup function to run before each benchmark task (cycle) */ setup?: Hook @@ -302,6 +313,11 @@ export interface FnOptions { */ beforeEach?: FnHook + /** + * Retain samples for this task, overriding the bench-level retainSamples option + */ + retainSamples?: boolean + /** * An AbortSignal for aborting this specific task * @@ -383,6 +399,21 @@ export interface ResolvedBenchOptions extends BenchOptions { warmupTime: NonNullable } +/** + * A type representing a samples-array with at least one number. + */ +export type Samples = [number, ...number[]] + +/** + * A type representing a sorted samples-array with at least one number. + */ +export type SortedSamples = Samples & { + /** + * A unique symbol to identify sorted samples + */ + readonly __sorted__: unique symbol +} + /** * The statistics object */ @@ -458,9 +489,14 @@ export interface Statistics { rme: number /** - * samples + * samples used to calculate the statistics + */ + samples: SortedSamples | undefined + + /** + * samples count */ - samples: number[] + samplesCount: number /** * standard deviation diff --git a/src/utils.ts b/src/utils.ts index 90ea106..5f84472 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,7 +2,14 @@ // Portions copyright QuiiBz. 2023-2024. All Rights Reserved. import type { Task } from './task' -import type { ConsoleTableConverter, Fn, JSRuntime, Statistics } from './types' +import type { + ConsoleTableConverter, + Fn, + JSRuntime, + Samples, + SortedSamples, + Statistics, +} from './types' import { emptyFunction, tTable } from './constants' @@ -251,16 +258,9 @@ export const isFnAsyncResource = (fn: Fn | null | undefined): boolean => { } /** - * A type representing a samples-array with at least one number. - */ -export type Samples = [number, ...number[]] - -export type SortedSamples = Samples & { readonly __sorted__: unique symbol } - -/** - * Checks whether a value is a Samples type. - * @param value - the value to check - * @returns whether the value is a Samples type, meaning a non-empty array of numbers + * Checks if a value is a Samples type. + * @param value - value to check + * @returns if the value is a Samples type, meaning a non-empty array of numbers */ export const isValidSamples = ( value: number[] | undefined @@ -418,9 +418,10 @@ export function absoluteDeviationMedian ( * Computes the statistics of a sample. * The sample must be sorted. * @param samples - the sorted sample + * @param retainSamples - whether to keep the samples in the statistics * @returns the statistics of the sample */ -export const getStatisticsSorted = (samples: SortedSamples): Statistics => { +export function getStatisticsSorted (samples: SortedSamples, retainSamples = false): Statistics { const { mean, vr } = meanAndVariance(samples) const sd = Math.sqrt(vr) const sem = sd / Math.sqrt(samples.length) @@ -447,7 +448,8 @@ export const getStatisticsSorted = (samples: SortedSamples): Statistics => { p995: quantileSorted(samples, 0.995), p999: quantileSorted(samples, 0.999), rme, - samples, + samples: retainSamples ? samples : undefined, + samplesCount: samples.length, sd, sem, variance: vr, @@ -504,7 +506,7 @@ export const defaultConvertTaskResultForConsoleTable: ConsoleTableConverter = ( 'Latency med (ns)': `${formatNumber(mToNs(task.result.latency.p50), 5, 2)} \xb1 ${formatNumber(mToNs(task.result.latency.mad), 5, 2)}`, 'Throughput avg (ops/s)': `${Math.round(task.result.throughput.mean).toString()} \xb1 ${task.result.throughput.rme.toFixed(2)}%`, 'Throughput med (ops/s)': `${Math.round(task.result.throughput.p50).toString()} \xb1 ${Math.round(task.result.throughput.mad).toString()}`, - Samples: task.result.latency.samples.length, + Samples: task.result.latency.samplesCount, } : state !== 'errored' ? { diff --git a/test/concurrency-iteration-limit.test.ts b/test/concurrency-iteration-limit.test.ts index 157e6e9..6a281ba 100644 --- a/test/concurrency-iteration-limit.test.ts +++ b/test/concurrency-iteration-limit.test.ts @@ -31,7 +31,7 @@ test('iteration limit not exceeded with task concurrency', async () => { expect(callCount).toBe(10) expect(task.runs).toBe(10) - expect(task.result.latency.samples.length).toBe(10) + expect(task.result.latency.samplesCount).toBe(10) }) test('iteration limit not exceeded with high concurrency', async () => { @@ -62,7 +62,7 @@ test('iteration limit not exceeded with high concurrency', async () => { expect(callCount).toBe(100) expect(task.runs).toBe(100) - expect(task.result.latency.samples.length).toBe(100) + expect(task.result.latency.samplesCount).toBe(100) }) test('iteration limit edge case - limit equals threshold', async () => { diff --git a/test/statistics.test.ts b/test/statistics.test.ts index 2c46fca..a74564a 100644 --- a/test/statistics.test.ts +++ b/test/statistics.test.ts @@ -25,7 +25,7 @@ test('statistics (async)', async () => { expect(fooTask.result.period).toBeTypeOf('number') // latency statistics expect(fooTask.result.latency).toBeTypeOf('object') - expect(Array.isArray(fooTask.result.latency.samples)).toBe(true) + expect(fooTask.result.latency.samplesCount).toBeTypeOf('number') expect(fooTask.result.latency.min).toBeTypeOf('number') expect(fooTask.result.latency.max).toBeTypeOf('number') expect(fooTask.result.latency.mean).toBeTypeOf('number') @@ -45,7 +45,7 @@ test('statistics (async)', async () => { expect(fooTask.result.latency.p999).toBeTypeOf('number') // throughput statistics expect(fooTask.result.throughput).toBeTypeOf('object') - expect(Array.isArray(fooTask.result.throughput.samples)).toBe(true) + expect(fooTask.result.throughput.samplesCount).toBeTypeOf('number') expect(fooTask.result.throughput.max).toBeTypeOf('number') expect(fooTask.result.throughput.mean).toBeTypeOf('number') expect(fooTask.result.throughput.variance).toBeTypeOf('number') @@ -86,7 +86,7 @@ test('statistics (sync)', () => { expect(fooTask.result.period).toBeTypeOf('number') // latency statistics expect(fooTask.result.latency).toBeTypeOf('object') - expect(Array.isArray(fooTask.result.latency.samples)).toBe(true) + expect(fooTask.result.latency.samplesCount).toBeTypeOf('number') expect(fooTask.result.latency.min).toBeTypeOf('number') expect(fooTask.result.latency.max).toBeTypeOf('number') expect(fooTask.result.latency.mean).toBeTypeOf('number') @@ -106,7 +106,7 @@ test('statistics (sync)', () => { expect(fooTask.result.latency.p999).toBeTypeOf('number') // throughput statistics expect(fooTask.result.throughput).toBeTypeOf('object') - expect(Array.isArray(fooTask.result.throughput.samples)).toBe(true) + expect(fooTask.result.throughput.samplesCount).toBeTypeOf('number') expect(fooTask.result.throughput.max).toBeTypeOf('number') expect(fooTask.result.throughput.mean).toBeTypeOf('number') expect(fooTask.result.throughput.variance).toBeTypeOf('number') @@ -124,3 +124,108 @@ test('statistics (sync)', () => { expect(fooTask.result.throughput.p995).toBeTypeOf('number') expect(fooTask.result.throughput.p999).toBeTypeOf('number') }) + +test('statistics retainSamples true', () => { + const bench = new Bench({ iterations: 32, retainSamples: true, time: 100 }) + bench.add('foo', () => { + // noop + }) + bench.runSync() + + const fooTask = bench.getTask('foo') + expect(fooTask).toBeDefined() + if (!fooTask) return + + expect(fooTask.result).toBeDefined() + + expect(fooTask.result.state).toBe('completed') + if (fooTask.result.state !== 'completed') return + + // latency statistics + expect(fooTask.result.latency).toBeTypeOf('object') + expect(fooTask.result.latency.samples).toBeTypeOf('object') +}) + +test('statistics retainSamples false', () => { + const bench = new Bench({ iterations: 32, retainSamples: false, time: 100 }) + bench.add('foo', () => { + // noop + }) + bench.runSync() + + const fooTask = bench.getTask('foo') + expect(fooTask).toBeDefined() + if (!fooTask) return + + expect(fooTask.result).toBeDefined() + + expect(fooTask.result.state).toBe('completed') + if (fooTask.result.state !== 'completed') return + + // latency statistics + expect(fooTask.result.latency).toBeTypeOf('object') + expect(fooTask.result.latency.samples).toBeTypeOf('undefined') +}) + +test('statistics retainSamples default is false', () => { + const bench = new Bench({ iterations: 32, time: 100 }) + bench.add('foo', () => { + // noop + }) + bench.runSync() + + const fooTask = bench.getTask('foo') + expect(fooTask).toBeDefined() + if (!fooTask) return + + expect(fooTask.result).toBeDefined() + + expect(fooTask.result.state).toBe('completed') + if (fooTask.result.state !== 'completed') return + + // latency statistics + expect(fooTask.result.latency).toBeTypeOf('object') + expect(fooTask.result.latency.samples).toBeTypeOf('undefined') +}) + +test('statistics retainSamples false on bench level but retainSamples true on task level', () => { + const bench = new Bench({ iterations: 32, retainSamples: false, time: 100 }) + bench.add('foo', () => { + // noop + }, { retainSamples: true }) + bench.runSync() + + const fooTask = bench.getTask('foo') + expect(fooTask).toBeDefined() + if (!fooTask) return + + expect(fooTask.result).toBeDefined() + + expect(fooTask.result.state).toBe('completed') + if (fooTask.result.state !== 'completed') return + + // latency statistics + expect(fooTask.result.latency).toBeTypeOf('object') + expect(fooTask.result.latency.samples).toBeTypeOf('object') +}) + +test('statistics retainSamples true on bench level but retainSamples false on task level', () => { + const bench = new Bench({ iterations: 32, retainSamples: true, time: 100 }) + bench.add('foo', () => { + // noop + }, { retainSamples: false }) + bench.runSync() + + const fooTask = bench.getTask('foo') + expect(fooTask).toBeDefined() + if (!fooTask) return + + expect(fooTask.result).toBeDefined() + + expect(fooTask.result.state).toBe('completed') + if (fooTask.result.state !== 'completed') return + + // latency statistics + expect(fooTask.result.latency).toBeTypeOf('object') + expect(fooTask.result.latency.samples).toBeTypeOf('undefined') +}) diff --git a/test/utils-absolute-deviation-median.test.ts b/test/utils-absolute-deviation-median.test.ts index ee019df..86a33b3 100644 --- a/test/utils-absolute-deviation-median.test.ts +++ b/test/utils-absolute-deviation-median.test.ts @@ -1,10 +1,8 @@ import { describe, expect, it } from 'vitest' -import { - absoluteDeviationMedian, - type Samples, - type SortedSamples, -} from '../src/utils' +import type { Samples, SortedSamples } from '../src/types' + +import { absoluteDeviationMedian } from '../src/utils' import { toSortedSamples } from './utils' // Helper: calculate median of a sorted array diff --git a/test/utils-get-statistics-sorted.test.ts b/test/utils-get-statistics-sorted.test.ts index a98a551..92d544f 100644 --- a/test/utils-get-statistics-sorted.test.ts +++ b/test/utils-get-statistics-sorted.test.ts @@ -1,88 +1,108 @@ import { expect, test } from 'vitest' -import { getStatisticsSorted, type SortedSamples } from '../src/utils' +import { + getStatisticsSorted, +} from '../src/utils' +import { toSortedSamples } from './utils' test('getStatisticsSorted', () => { - let stats = getStatisticsSorted([ - 1, 2, 3, 4, 5, 6, - ] as unknown as SortedSamples) - expect(stats.min).toBe(1) - expect(stats.max).toBe(6) - expect(stats.df).toBe(5) - expect(stats.critical).toBe(2.57058183661474) - expect(stats.mean).toBe(3.5) - expect(stats.variance).toBe(3.5) - expect(stats.sd).toBe(1.8708286933869707) - expect(stats.sem).toBe(0.7637626158259734) - expect(stats.moe).toBe(1.9633143077276087) - expect(stats.rme).toBe((stats.moe / stats.mean) * 100) - expect(stats.p50).toBe(3.5) - expect(stats.p75).toBe(4.75) - expect(stats.p99).toBe(5.95) - expect(stats.p995).toBe(5.975) - expect(stats.p999).toBe(5.995) - expect(stats.mad).toBe(1.5) - expect(stats.aad).toBe(1.5) - stats = getStatisticsSorted([1, 2, 3, 4, 5, 6, 7] as unknown as SortedSamples) - expect(stats.min).toBe(1) - expect(stats.max).toBe(7) - expect(stats.df).toBe(6) - expect(stats.critical).toBe(2.446911848791681) - expect(stats.mean).toBe(4) - expect(stats.variance).toBe(4.666666666666667) - expect(stats.sd).toBe(2.160246899469287) - expect(stats.sem).toBe(0.816496580927726) - expect(stats.moe).toBe(1.9978951583699485) - expect(stats.rme).toBe((stats.moe / stats.mean) * 100) - expect(stats.p50).toBe(4) - expect(stats.p75).toBe(5.5) - expect(stats.p99).toBe(6.9399999999999995) - expect(stats.p995).toBe(6.97) - expect(stats.p999).toBe(6.994) - expect(stats.mad).toBe(2) - expect(stats.aad).toBe(1.7142857142857142) + let stats = getStatisticsSorted(toSortedSamples([1, 2, 3, 4, 5, 6])) + expect(stats.min, 'min').toBe(1) + expect(stats.max, 'max').toBe(6) + expect(stats.df, 'df').toBe(5) + expect(stats.critical, 'critical').toBe(2.57058183661474) + expect(stats.mean, 'mean').toBe(3.5) + expect(stats.variance, 'variance').toBe(3.5) + expect(stats.sd, 'sd').toBe(1.8708286933869707) + expect(stats.sem, 'sem').toBe(0.7637626158259734) + expect(stats.moe, 'moe').toBe(1.9633143077276087) + expect(stats.rme, 'rme').toBe((stats.moe / stats.mean) * 100) + expect(stats.p50, 'p50').toBe(3.5) + expect(stats.p75, 'p75').toBe(4.75) + expect(stats.p99, 'p99').toBe(5.95) + expect(stats.p995, 'p995').toBe(5.975) + expect(stats.p999, 'p999').toBe(5.995) + expect(stats.mad, 'mad').toBe(1.5) + expect(stats.aad, 'aad').toBe(1.5) + stats = getStatisticsSorted(toSortedSamples([1, 2, 3, 4, 5, 6, 7])) + expect(stats.min, 'min').toBe(1) + expect(stats.max, 'max').toBe(7) + expect(stats.df, 'df').toBe(6) + expect(stats.critical, 'critical').toBe(2.446911848791681) + expect(stats.mean, 'mean').toBe(4) + expect(stats.variance, 'variance').toBe(4.666666666666667) + expect(stats.sd, 'sd').toBe(2.160246899469287) + expect(stats.sem, 'sem').toBe(0.816496580927726) + expect(stats.moe, 'moe').toBe(1.9978951583699485) + expect(stats.rme, 'rme').toBe((stats.moe / stats.mean) * 100) + expect(stats.p50, 'p50').toBe(4) + expect(stats.p75, 'p75').toBe(5.5) + expect(stats.p99, 'p99').toBe(6.9399999999999995) + expect(stats.p995, 'p995').toBe(6.97) + expect(stats.p999, 'p999').toBe(6.994) + expect(stats.mad, 'mad').toBe(2) + expect(stats.aad, 'aad').toBe(1.7142857142857142) }) test('getStatisticsSorted - sample [0]', () => { - const stats = getStatisticsSorted([0] as unknown as SortedSamples) - expect(stats.min).toBe(0) - expect(stats.max).toBe(0) - expect(stats.df).toBe(0) - expect(stats.critical).toBe(12.706204736432102) - expect(stats.mean).toBe(0) - expect(stats.variance).toBe(0) - expect(stats.sd).toBe(0) - expect(stats.sem).toBe(0) - expect(stats.moe).toBe(0) - expect(stats.rme).toBe(Number.POSITIVE_INFINITY) - expect(stats.p50).toBe(0) - expect(stats.p75).toBe(0) - expect(stats.p99).toBe(0) - expect(stats.p995).toBe(0) - expect(stats.p999).toBe(0) - expect(stats.mad).toBe(0) - expect(stats.aad).toBe(0) + const stats = getStatisticsSorted(toSortedSamples([0])) + expect(stats.min, 'min').toBe(0) + expect(stats.max, 'max').toBe(0) + expect(stats.df, 'df').toBe(0) + expect(stats.critical, 'critical').toBe(12.706204736432102) + expect(stats.mean, 'mean').toBe(0) + expect(stats.variance, 'variance').toBe(0) + expect(stats.sd, 'sd').toBe(0) + expect(stats.sem, 'sem').toBe(0) + expect(stats.moe, 'moe').toBe(0) + expect(stats.rme, 'rme').toBe(Infinity) + expect(stats.p50, 'p50').toBe(0) + expect(stats.p75, 'p75').toBe(0) + expect(stats.p99, 'p99').toBe(0) + expect(stats.p995, 'p995').toBe(0) + expect(stats.p999, 'p999').toBe(0) + expect(stats.mad, 'mad').toBe(0) + expect(stats.aad, 'aad').toBe(0) }) test('getStatisticsSorted - big sample [0, 0, ...]', () => { - const stats = getStatisticsSorted( - new Array(2000).fill(0) as unknown as SortedSamples - ) - expect(stats.min).toBe(0) - expect(stats.max).toBe(0) - expect(stats.df).toBe(1999) - expect(stats.critical).toBe(1.96) - expect(stats.mean).toBe(0) - expect(stats.variance).toBe(0) - expect(stats.sd).toBe(0) - expect(stats.sem).toBe(0) - expect(stats.moe).toBe(0) - expect(stats.rme).toBe(Number.POSITIVE_INFINITY) - expect(stats.p50).toBe(0) - expect(stats.p75).toBe(0) - expect(stats.p99).toBe(0) - expect(stats.p995).toBe(0) - expect(stats.p999).toBe(0) - expect(stats.mad).toBe(0) - expect(stats.aad).toBe(0) + const stats = getStatisticsSorted(toSortedSamples([0, ...new Array(1999).fill(0)])) + expect(stats.min, 'min').toBe(0) + expect(stats.max, 'max').toBe(0) + expect(stats.df, 'df').toBe(1999) + expect(stats.critical, 'critical').toBe(1.96) + expect(stats.mean, 'mean').toBe(0) + expect(stats.variance, 'variance').toBe(0) + expect(stats.sd, 'sd').toBe(0) + expect(stats.sem, 'sem').toBe(0) + expect(stats.moe, 'moe').toBe(0) + expect(stats.rme, 'rme').toBe(Infinity) + expect(stats.p50, 'p50').toBe(0) + expect(stats.p75, 'p75').toBe(0) + expect(stats.p99, 'p99').toBe(0) + expect(stats.p995, 'p995').toBe(0) + expect(stats.p999, 'p999').toBe(0) + expect(stats.mad, 'mad').toBe(0) + expect(stats.aad, 'aad').toBe(0) +}) + +test('getStatisticsSorted - big sample [0, 1, 2, 3, ...(n+1)[]]', () => { + const stats = getStatisticsSorted(toSortedSamples([0, ...new Array(1999).fill(0).map((_, i) => i + 1)])) + expect(stats.min, 'min').toBe(0) + expect(stats.max, 'max').toBe(1999) + expect(stats.df, 'df').toBe(1999) + expect(stats.critical, 'critical').toBe(1.96) + expect(stats.mean, 'mean').toBe(999.5) + expect(stats.variance, 'variance').toBe(333500) + expect(stats.sd, 'sd').toBe(577.4945887192364) + expect(stats.sem, 'sem').toBe(12.913171570144957) + expect(stats.moe, 'moe').toBe(25.309816277484117) + expect(stats.rme, 'rme').toBe(2.532247751624224) + expect(stats.p50, 'p50').toBeCloseTo(999.5) + expect(stats.p75, 'p75').toBeCloseTo(1499.25) + expect(stats.p99, 'p99').toBeCloseTo(1979.01) + expect(stats.p995, 'p995').toBeCloseTo(1989) + expect(stats.p999, 'p999').toBeCloseTo(1997) + expect(stats.mad, 'mad').toBe(500) + expect(stats.aad, 'aad').toBeCloseTo(500) }) diff --git a/test/utils-mean-and-variance.test.ts b/test/utils-mean-and-variance.test.ts index 10bd46b..7e4a30e 100644 --- a/test/utils-mean-and-variance.test.ts +++ b/test/utils-mean-and-variance.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest' -import { meanAndVariance, type Samples } from '../src/utils' +import { Samples } from '../src/types' +import { meanAndVariance } from '../src/utils' describe('meanAndVariance()', () => { it('returns 0 for a single sample', () => { diff --git a/test/utils-sort-samples.test.ts b/test/utils-sort-samples.test.ts index 3640efa..6bd8b07 100644 --- a/test/utils-sort-samples.test.ts +++ b/test/utils-sort-samples.test.ts @@ -1,15 +1,22 @@ import { expect, test } from 'vitest' -import { type Samples, sortSamples } from '../src/utils' +import { + isValidSamples, + sortSamples +} from '../src/utils' test('sortSamples', () => { - const samples: Samples = [1, 2, 3, 4, 5, 0] + const samples: number[] = [1, 2, 3, 4, 5, 0] - expect(sortSamples(samples)).toBe(undefined) // eslint-disable-line - expect(samples[0]).toBe(0) - expect(samples[1]).toBe(1) - expect(samples[2]).toBe(2) - expect(samples[3]).toBe(3) - expect(samples[4]).toBe(4) - expect(samples[5]).toBe(5) + if (isValidSamples(samples)) { + expect(sortSamples(samples)).toBe(undefined) // eslint-disable-line + expect(samples[0]).toBe(0) + expect(samples[1]).toBe(1) + expect(samples[2]).toBe(2) + expect(samples[3]).toBe(3) + expect(samples[4]).toBe(4) + expect(samples[5]).toBe(5) + } else { + throw new Error('Invalid samples') + } }) diff --git a/test/utils.ts b/test/utils.ts index 2476be2..5b4fdc9 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -1,4 +1,6 @@ -import { type Samples, type SortedSamples, sortFn } from '../src/utils' +import type { Samples, SortedSamples } from '../src/types' + +import { sortFn } from '../src/utils' const nil32 = typeof SharedArrayBuffer !== 'undefined' &&