# Stopwatch

<a id="stopwatch"></a>

# Stopwatch

```cpp
#include <icy/datetime.h>

class Stopwatch
```

[Defined in src/base/include/icy/datetime.h:1733](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1733)

A simple facility to measure time intervals with microsecond resolution.

The [Stopwatch](#stopwatch) uses the current system time, so if the system time changes the measured time will be incorrect.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Stopwatch`](#stopwatch-1)  |  |
|  | [`~Stopwatch`](#stopwatch-2)  |  |
| `void` | [`start`](#start-4)  | Starts (or restarts) the stopwatch. |
| `void` | [`stop`](#stop-2)  | Stops or pauses the stopwatch. |
| `void` | [`reset`](#reset-7)  | Resets the stopwatch. |
| `void` | [`restart`](#restart)  | Resets and starts the stopwatch. |
| [`Timestamp::TimeDiff`](https://auscaster.com/icey/docs/api-reference/icy-Timestamp.md#timediff-1) | [`elapsed`](#elapsed) `const` | Returns the elapsed time in microseconds since the stopwatch started. |
| `int` | [`elapsedSeconds`](#elapsedseconds) `const` | Returns the number of seconds elapsed since the stopwatch started. |
| `int` | [`elapsedMilliseconds`](#elapsedmilliseconds) `const` | Returns the number of milliseconds elapsed since the stopwatch started. |

---

<a id="stopwatch-1"></a>

### Stopwatch

```cpp
Stopwatch()
```

[Defined in src/base/include/icy/datetime.h:1736](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1736)

---

<a id="stopwatch-2"></a>

### ~Stopwatch

```cpp
~Stopwatch()
```

[Defined in src/base/include/icy/datetime.h:1737](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1737)

---

<a id="start-4"></a>

### start

```cpp
void start()
```

[Defined in src/base/include/icy/datetime.h:1740](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1740)

Starts (or restarts) the stopwatch.

---

<a id="stop-2"></a>

### stop

```cpp
void stop()
```

[Defined in src/base/include/icy/datetime.h:1743](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1743)

Stops or pauses the stopwatch.

---

<a id="reset-7"></a>

### reset

```cpp
void reset()
```

[Defined in src/base/include/icy/datetime.h:1746](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1746)

Resets the stopwatch.

---

<a id="restart"></a>

### restart

```cpp
void restart()
```

[Defined in src/base/include/icy/datetime.h:1749](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1749)

Resets and starts the stopwatch.

---

<a id="elapsed"></a>

### elapsed

`const`

```cpp
Timestamp::TimeDiff elapsed() const
```

[Defined in src/base/include/icy/datetime.h:1753](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1753)

Returns the elapsed time in microseconds since the stopwatch started.

---

<a id="elapsedseconds"></a>

### elapsedSeconds

`const`

```cpp
int elapsedSeconds() const
```

[Defined in src/base/include/icy/datetime.h:1757](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1757)

Returns the number of seconds elapsed since the stopwatch started.

---

<a id="elapsedmilliseconds"></a>

### elapsedMilliseconds

`const`

```cpp
int elapsedMilliseconds() const
```

[Defined in src/base/include/icy/datetime.h:1761](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1761)

Returns the number of milliseconds elapsed since the stopwatch started.

## Public Static Methods

| Return | Name | Description |
|--------|------|-------------|
| [`Timestamp::TimeVal`](https://auscaster.com/icey/docs/api-reference/icy-Timestamp.md#timeval) | [`resolution`](#resolution) `static` | Returns the resolution of the stopwatch. |

---

<a id="resolution"></a>

### resolution

`static`

```cpp
static Timestamp::TimeVal resolution()
```

[Defined in src/base/include/icy/datetime.h:1764](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1764)

Returns the resolution of the stopwatch.

## Private Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`Timestamp`](https://auscaster.com/icey/docs/api-reference/icy-Timestamp.md#timestamp-2) | [`_start`](#_start)  |  |
| [`Timestamp::TimeDiff`](https://auscaster.com/icey/docs/api-reference/icy-Timestamp.md#timediff-1) | [`_elapsed`](#_elapsed)  |  |
| `bool` | [`_running`](#_running)  |  |

---

<a id="_start"></a>

### _start

```cpp
Timestamp _start
```

Type: [`Timestamp`](https://auscaster.com/icey/docs/api-reference/icy-Timestamp.md#timestamp-2)

[Defined in src/base/include/icy/datetime.h:1770](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1770)

---

<a id="_elapsed"></a>

### _elapsed

```cpp
Timestamp::TimeDiff _elapsed
```

Type: [`Timestamp::TimeDiff`](https://auscaster.com/icey/docs/api-reference/icy-Timestamp.md#timediff-1)

[Defined in src/base/include/icy/datetime.h:1771](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1771)

---

<a id="_running"></a>

### _running

```cpp
bool _running
```

[Defined in src/base/include/icy/datetime.h:1772](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1772)

## Private Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Stopwatch`](#stopwatch-3)  | Deleted constructor. |
| [`Stopwatch`](#stopwatch) & | [`operator=`](#operator-95)  | Deleted assignment operator. |

---

<a id="stopwatch-3"></a>

### Stopwatch

```cpp
Stopwatch(const Stopwatch &) = delete
```

[Defined in src/base/include/icy/datetime.h:1767](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1767)

Deleted constructor.

---

<a id="operator-95"></a>

### operator=

```cpp
Stopwatch & operator=(const Stopwatch &) = delete
```

[Defined in src/base/include/icy/datetime.h:1768](https://github.com/auscaster/icey/blob/main/src/base/include/icy/datetime.h#L1768)

Deleted assignment operator.
