> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man9/microuptime.9.md).

# microuptime.9

`binuptime` — 获取自启动以来经过的时间

## 名称

`binuptime`, `getbinuptime`, `microuptime`, `getmicrouptime`, `nanouptime`, `getnanouptime`, `sbinuptime`, `getsbinuptime`

## 概要

```c
#include <sys/time.h>
```

```c
void
binuptime(struct bintime *bt)

void
getbinuptime(struct bintime *bt)

void
microuptime(struct timeval *tv)

void
getmicrouptime(struct timeval *tv)

void
nanouptime(struct timespec *ts)

void
getnanouptime(struct timespec *tsp)

sbintime_t
sbinuptime(void)

sbintime_t
getsbinuptime(void)
```

## 描述

`binuptime` 和 `getbinuptime` 函数将自启动以来经过的时间以 `struct bintime` 的形式存储在 `bt` 所指定的地址处。`microuptime` 和 `getmicrouptime` 函数执行相同的功能，但将经过的时间记录为 `struct timeval`。类似地，`nanouptime` 和 `getnanouptime` 函数将经过的时间存储为 `struct timespec`。`sbinuptime` 和 `getsbinuptime` 函数以 `sbintime_t` 的形式返回自启动以来经过的时间。

`binuptime`、`microuptime`、`nanouptime` 和 `sbinuptime` 函数总是查询 timecounter 以尽可能精确地返回当前时间。而 `getbinuptime`、`getmicrouptime`、`getnanouptime` 和 `getsbinuptime` 函数是抽象层，返回精度较低但获取速度更快的时间。

`getbinuptime`、`getmicrouptime`、`getnanouptime` 和 `getsbinuptime` 函数的设计意图是在定时器精度与执行时间之间贯彻用户的偏好。

## 参见

bintime(9), [get\_cyclecount(9)](/man/man9/get_cyclecount.9.md), getbintime(9), getmicrotime(9), getnanotime(9), [microtime(9)](/man/man9/microtime.9.md), nanotime(9), [tvtohz(9)](/man/man9/tvtohz.9.md)

## 作者

本手册页由 Kelly Yancey <kbyanc@posi.net> 编写。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man9/microuptime.9.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
