1.0.4 • Published 12 months ago

@liu7i/qi_benchmark v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

qBenchmark

用于对比函数性能 依赖于window.performance.now api

安装

pnpm add @liu7i/qi_benchmark

使用方法示例

import { QBenchmark } from '@liu7i/qi_benchmark';

// 实例化
const benchmark = new QBenchmark();

function test1(){
   // todo
}

function test2(){
  // todo
}

// 添加需要测试的函数
benchmark.add({
    name: "test1",
    taskContent: test1,
    numberOfTimes: 10,
});

benchmark.add({
    name: "test2",
    taskContent: test2,
    numberOfTimes: 10,
});

// 开始测试
benchmark.run();  // 会返回执行结果,可以自己进行分析

// 进行简单的分析 返回平均用时等信息
const analysis = benchmark.analysis();

console.log("analysis:", analysis);

API

方法作用参数返回值
add添加任务IWorkListvoid
run执行任务voidIRunningResults
analysis分析结果voidIAnalysis[]

interface

export interface IWorkList {
  /** @param 名称 需要唯一 */
  name: string;
  /** @param 函数体 */
  taskContent: Function;
  /** @param 需要执行的次数 默认为100 */
  numberOfTimes?: number;
}
export interface IRecord {
  /** @param 执行顺序 */
  order: number;
  /** @param 执行所属函数体 */
  taskName: string;
  /** @param 执行耗时 单位ms */
  executionTime: number;
}
export interface IAnalysis {
  /** @param 任务名称 */
  taskName: string;
  /** @param 总耗时 */
  total: number;
  /** @param 平均耗时 */
  average: number;
  /** @param 执行次数 */
  times: number;
}
1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago