npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@neosjs/timer-logger

v1.0.0

Published

A timer logger for NeosJS

Downloads

7

Readme

@neosjs/timer-logger

Npm Version Npm Week Downloads Npm Month Downloads Minzip License Timer Logger Githu Ci

一个高性能、类型安全的计时器日志记录库,支持浏览器和 Node.js 环境。

✨ 特性

  • 🚀 高性能: 使用高精度时间 API,提供纳秒级精度
  • 🌐 跨平台: 支持浏览器和 Node.js 环境
  • 📝 类型安全: 完整的 TypeScript 类型定义
  • 🎯 灵活配置: 支持自定义格式化选项
  • 🔧 易于使用: 简洁的 API 设计
  • 📦 轻量级: 仅 2.7KB (gzipped)

安装

pnpm add @neosjs/timer-logger

npm install @neosjs/timer-logger

yarn add @neosjs/timer-logger

快速开始

基本用法

import timerLogger from '@neosjs/timer-logger'

// 启用计时器
timerLogger.setEnabled(true)

// 开始计时
const timer = timerLogger.start('my-task')
// ... 执行一些操作
timer?.end('任务完成')

// 或者使用标签方式
timerLogger.start('another-task')
// ... 执行一些操作
timerLogger.end('another-task', '另一个任务完成')

高级用法

import { createTimerLogger } from '@neosjs/timer-logger'

// 创建自定义实例
const customLogger = createTimerLogger({
  enabled: true
})

customLogger.start('custom-task')
// ... 执行操作
customLogger.end('custom-task', '自定义任务')

获取总时间

import timerLogger from '@neosjs/timer-logger'

timerLogger.setEnabled(true)

// 开始多个计时器
timerLogger.start('task1')
timerLogger.start('task2')
timerLogger.start('task3')

// ... 执行操作

// 获取各个计时器的时间
console.log('task1 时间:', timerLogger.getLabelTime('task1'), 'ms')
console.log('task2 时间:', timerLogger.getLabelTime('task2'), 'ms')

// 获取所有计时器的总时间
const totalTime = timerLogger.getTotalTime()
console.log('总时间:', totalTime, 'ms')

API 参考

TimerLogger (默认实例)

方法

  • setEnabled(enabled: boolean): 启用或禁用计时器
  • isEnabled(): boolean: 检查是否启用
  • start(label?: string): BaseTimerLogger | undefined: 开始计时
  • end(label: string, overrideLabel?: string, options?: TimeFormatOptions): void: 结束计时
  • get(label: string, options?: TimeFormatOptions): string | undefined: 获取计时结果
  • getLabelTime(label: string): number | undefined: 获取原始毫秒数
  • getTotalTime(): number: 获取所有活跃计时器的总时间
  • clear(label: string): boolean: 清除指定标签的计时器
  • reset(): void: 重置计时器

类型定义

interface TimerLoggerOptions {
  enabled?: boolean
}

type HrTime = readonly [number, number] // [秒, 纳秒]

环境支持

  • 浏览器: 使用 performance.now() API
  • Node.js: 使用 process.hrtime() API
  • 其他环境: 降级使用 Date.now()

License

MIT License © 2021-PRESENT NeosJS