Skip to content

Commit 00bd063

Browse files
committed
Add benchmarks
1 parent 15393a3 commit 00bd063

18 files changed

+1002
-130
lines changed

.github/workflows/benches.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Run Benchmarks
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
benchmarks:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout Repository
23+
uses: actions/checkout@v4
24+
25+
- name: Install Zig
26+
uses: goto-bus-stop/setup-zig@v2
27+
with:
28+
version: '0.15.1'
29+
30+
- name: Install Dependencies
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y make
34+
35+
- name: Run the Benchmarks
36+
run: make bench

.github/workflows/docs.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
name: Publish API Documentation
22

33
on:
4+
workflow_dispatch:
45
push:
56
tags:
67
- 'v*'
78

8-
workflow_dispatch:
9-
109
permissions:
1110
contents: write
1211

.github/workflows/lints.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
name: Run Linter Checks
22

33
on:
4+
workflow_dispatch:
45
push:
5-
branches:
6-
- main
76
tags:
87
- 'v*'
9-
108
pull_request:
119
branches:
1210
- main
1311

14-
workflow_dispatch:
15-
1612
permissions:
1713
contents: read
1814

.github/workflows/tests.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
name: Run Tests
22

33
on:
4+
workflow_dispatch:
45
push:
56
branches:
67
- main
78
tags:
89
- 'v*'
9-
1010
pull_request:
1111
branches:
1212
- main
1313

14-
workflow_dispatch:
15-
1614
permissions:
1715
contents: read
1816

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,33 @@
77
<h2>Ordered</h2>
88

99
[![Tests](https://img.shields.io/github/actions/workflow/status/CogitatorTech/ordered/tests.yml?label=tests&style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/ordered/actions/workflows/tests.yml)
10-
[![CodeFactor](https://img.shields.io/codefactor/grade/github/CogitatorTech/ordered?label=code%20quality&style=flat&labelColor=282c34&logo=codefactor)](https://www.codefactor.io/repository/github/CogitatorTech/ordered)
11-
[![Zig Version](https://img.shields.io/badge/Zig-0.15.1-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
10+
[![Benchmarks](https://img.shields.io/github/actions/workflow/status/CogitatorTech/ordered/benches.yml?label=benches&style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/ordered/actions/workflows/benches.yml)
11+
[![CodeFactor](https://img.shields.io/codefactor/grade/github/CogitatorTech/ordered?label=quality&style=flat&labelColor=282c34&logo=codefactor)](https://www.codefactor.io/repository/github/CogitatorTech/ordered)
1212
[![Docs](https://img.shields.io/badge/docs-view-blue?style=flat&labelColor=282c34&logo=read-the-docs)](https://CogitatorTech.github.io/ordered/)
1313
[![Examples](https://img.shields.io/badge/examples-view-green?style=flat&labelColor=282c34&logo=zig)](https://github.com/CogitatorTech/ordered/tree/main/examples)
14+
[![Zig Version](https://img.shields.io/badge/Zig-0.15.1-orange?logo=zig&labelColor=282c34)](https://ziglang.org/download/)
1415
[![Release](https://img.shields.io/github/release/CogitatorTech/ordered.svg?label=release&style=flat&labelColor=282c34&logo=github)](https://github.com/CogitatorTech/ordered/releases/latest)
1516
[![License](https://img.shields.io/badge/license-MIT-007ec6?label=license&style=flat&labelColor=282c34&logo=open-source-initiative)](https://github.com/CogitatorTech/ordered/blob/main/LICENSE)
1617

17-
A collection of data structures that keep data in order
18+
A collection of data structures that keep data in order in pure Zig
1819

1920
</div>
2021

2122
---
2223

23-
Ordered library includes fast and efficient implementations of popular data structures including
24+
Ordered is a Zig library that provides fast and efficient implementations of various popular data structures including
2425
B-tree, skip list, trie, and red-black tree for Zig programming language.
2526

2627
### Supported Data Structures
2728

2829
Currently supported data structures include:
2930

30-
- [B-tree](src/ordered/btree_map.zig): a balanced n-array tree that maintains the order of keys.
31-
- [Sorted set](src/ordered/sorted_set.zig): a set with ordered elements based on keys.
32-
- [Skip list](src/ordered/skip_list.zig): a probabilistic data structure that maintains sorted order using multiple linked lists.
33-
- [Trie](src/ordered/trie.zig): a prefix tree that supports efficient retrieval of keys with common prefixes.
34-
- [Red-black tree](src/ordered/red_black_tree.zig): A self-balancing binary search tree that maintains the order of keys
35-
- [Cartesian tree](src/ordered/cartesian_tree.zig): A binary tree that maintains both a binary search tree property on keys and a heap property on priorities.
31+
- [B-tree](src/ordered/btree_map.zig): A self-balancing search tree where nodes can have many children.
32+
- [Sorted Set](src/ordered/sorted_set.zig): A data structure that stores a collection of unique elements in a consistently sorted order.
33+
- [Skip List](src/ordered/skip_list.zig): A probabilistic data structure that uses multiple linked lists to create "express lanes" for fast, tree-like search.
34+
- [Trie](src/ordered/trie.zig): A tree where paths from the root represent prefixes which makes it extremely fast for tasks like text autocomplete.
35+
- [Red-black Tree](src/ordered/red_black_tree.zig): A self-balancing binary search tree that uses node colors to guarantee efficient operations.
36+
- [Cartesian Tree](src/ordered/cartesian_tree.zig): A binary tree that uniquely combines a binary search tree property for its keys with a heap** property for its values.
3637

3738
| # | Data Structure | Build Complexity | Memory Complexity | Search Complexity |
3839
|---|----------------|------------------|-------------------|----------------------|

benches/README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Benchmarks
1+
## Benchmarks
22

3-
This directory contains performance benchmarks for all data structures in the `ordered` library.
3+
This directory contains benchmarks for the data structures in the `ordered` library.
44

5-
## Running Benchmarks
5+
### Running Benchmarks
66

77
Each benchmark can be run using the following command pattern:
88

99
```bash
1010
zig build bench-<benchmark_name>
1111
```
1212

13-
### Available Benchmarks
13+
#### Available Benchmarks
1414

1515
- **BTreeMap**: `zig build bench-btree_map_bench`
1616
- **SortedSet**: `zig build bench-sorted_set_bench`
@@ -19,53 +19,53 @@ zig build bench-<benchmark_name>
1919
- **Trie**: `zig build bench-trie_bench`
2020
- **CartesianTree**: `zig build bench-cartesian_tree_bench`
2121

22-
## What Each Benchmark Tests
22+
### What Each Benchmark Tests
2323

24-
### BTreeMap Benchmark
24+
#### BTreeMap Benchmark
2525
- **Insert**: Sequential insertion of integers
2626
- **Lookup**: Finding all inserted keys
2727
- **Delete**: Removing all keys
2828

29-
### SortedSet Benchmark
30-
- **Add**: Adding elements while maintaining sorted order
29+
#### SortedSet Benchmark
30+
- **Add**: Adding elements while maintaining a sorted order
3131
- **Contains**: Checking if elements exist
3232
- **Remove**: Removing elements from the set
3333

34-
### RedBlackTree Benchmark
34+
#### RedBlackTree Benchmark
3535
- **Insert**: Inserting nodes with self-balancing
3636
- **Find**: Searching for nodes
3737
- **Remove**: Deleting nodes while maintaining balance
3838
- **Iterator**: In-order traversal performance
3939

40-
### SkipList Benchmark
40+
#### SkipList Benchmark
4141
- **Put**: Inserting key-value pairs with probabilistic levels
4242
- **Get**: Retrieving values by key
4343
- **Delete**: Removing key-value pairs
4444

45-
### Trie Benchmark
45+
#### Trie Benchmark
4646
- **Put**: Inserting strings with associated values
4747
- **Get**: Retrieving values by string key
4848
- **Contains**: Checking if strings exist
4949
- **Prefix Search**: Finding all keys with a common prefix
5050

51-
### CartesianTree Benchmark
51+
#### CartesianTree Benchmark
5252
- **Put**: Inserting key-value pairs with random priorities
5353
- **Get**: Retrieving values by key
5454
- **Remove**: Deleting nodes
5555
- **Iterator**: In-order traversal performance
5656

57-
## Benchmark Sizes
57+
### Benchmark Sizes
5858

5959
Each benchmark tests with multiple dataset sizes:
6060
- Small: 1,000 items
6161
- Medium: 10,000 items
6262
- Large: 50,000 - 100,000 items (varies by data structure)
6363

64-
## Build Configuration
64+
### Build Configuration
6565

6666
Benchmarks are compiled with `ReleaseFast` optimization mode for accurate performance measurements.
6767

68-
## Example Output
68+
### Example Output
6969

7070
```
7171
=== BTreeMap Benchmark ===
@@ -79,9 +79,9 @@ Lookup 10000 items: 2.10 ms (210 ns/op, found: 10000)
7979
Delete 10000 items: 4.15 ms (415 ns/op)
8080
```
8181

82-
## Notes
82+
### Notes
8383

8484
- All benchmarks use a simple integer or string key type for consistency
8585
- Times are reported in both total milliseconds and nanoseconds per operation
86-
- Memory allocations use `GeneralPurposeAllocator` for production-like behavior
87-
86+
- Memory allocations use `GeneralPurposeAllocator` for simulating a more realistic memory usage
87+
- Results may vary based on a hardware and system load

benches/b1_btree_map.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,3 @@ fn benchmarkDelete(allocator: std.mem.Allocator, size: usize) !void {
100100
ns_per_op,
101101
});
102102
}
103-

benches/b2_sorted_set.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,3 @@ fn benchmarkRemove(allocator: std.mem.Allocator, size: usize) !void {
9999
ns_per_op,
100100
});
101101
}
102-

benches/b3_red_black_tree.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,3 @@ fn benchmarkIterator(allocator: std.mem.Allocator, size: usize) !void {
135135
count,
136136
});
137137
}
138-

benches/b4_skip_list.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,3 @@ fn benchmarkDelete(allocator: std.mem.Allocator, size: usize) !void {
100100
ns_per_op,
101101
});
102102
}
103-

0 commit comments

Comments
 (0)