Skip to content

Commit 063fc95

Browse files
authored
Merge pull request #178 from Kaaserne/dev
Pairwise iterator, compile time improvements
2 parents 03b823a + f4e8dec commit 063fc95

File tree

212 files changed

+5703
-3028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+5703
-3028
lines changed

.github/workflows/clang.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
env:
22
CTEST_OUTPUT_ON_FAILURE: 1
3+
LIBCXX_STANDARDS_JSON: '["20","23"]'
34

45
on:
56
workflow_call:
@@ -30,15 +31,17 @@ jobs:
3031
run: sudo apt-get install -y clang-${{ matrix.version }}
3132

3233
- name: Install libc++ Clang ${{ matrix.version }}
33-
if: matrix.standard == '20'
34+
if: contains(fromJson(env.LIBCXX_STANDARDS_JSON), matrix.standard)
3435
run: sudo apt-get install -y libc++-${{ matrix.version }}-dev libc++abi-${{ matrix.version }}-dev
3536

3637
- name: Configure (install)
3738
env:
3839
CC: clang-${{ matrix.version }}
3940
CXX: clang-${{ matrix.version }}
4041
run: |
41-
if [ "${{ matrix.standard }}" = "20" ]; then
42+
sudo apt-get update && sudo apt-get install -y jq
43+
STDS=$(echo '${{ env.LIBCXX_STANDARDS_JSON }}' | jq -r '.[]' | xargs)
44+
if echo "$STDS" | grep -wq "${{ matrix.standard }}"; then
4245
CXX_FLAGS='-stdlib=libc++'
4346
else
4447
CXX_FLAGS=''
@@ -60,10 +63,12 @@ jobs:
6063

6164
- name: Configure tests
6265
run: |
63-
if [ "${{ matrix.standard }}" == "20" ]; then
64-
CXX_FLAGS="-stdlib=libc++"
66+
sudo apt-get update && sudo apt-get install -y jq
67+
STDS=$(echo '${{ env.LIBCXX_STANDARDS_JSON }}' | jq -r '.[]' | xargs)
68+
if echo "$STDS" | grep -wq "${{ matrix.standard }}"; then
69+
CXX_FLAGS='-stdlib=libc++'
6570
else
66-
CXX_FLAGS=""
71+
CXX_FLAGS=''
6772
fi
6873
cmake -S tests -B build/tests -G Ninja \
6974
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \

.github/workflows/msvc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66

77
jobs:
88
msvc:
9-
name: msvc-${{ matrix.standard }} (C++${{ matrix.standard }})
9+
name: msvc-${{ matrix.os }} (C++${{ matrix.standard }})
1010

1111
strategy:
1212
fail-fast: false

README.md

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[![Build status](https://github.com/MarcDirven/cpp-lazy/workflows/Continuous%20Integration/badge.svg)](https://github.com/MarcDirven/cpp-lazy/actions)
1+
[![Build status](https://github.com/Kaaserne/cpp-lazy/workflows/Continuous%20Integration/badge.svg)](https://github.com/Kaaserne/cpp-lazy/actions)
22
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3-
[![CodeQL](https://github.com/MarcDirven/cpp-lazy/actions/workflows/codeql.yml/badge.svg)](https://github.com/MarcDirven/cpp-lazy/actions/workflows/codeql.yml)
3+
[![CodeQL](https://github.com/Kaaserne/cpp-lazy/actions/workflows/codeql.yml/badge.svg)](https://github.com/Kaaserne/cpp-lazy/actions/workflows/codeql.yml)
44

55
![](https://i.ibb.co/ccn2V8N/Screenshot-2021-05-05-Make-A-High-Quality-Logo-In-Just-5-Minutes-For-Under-30-v1-cropped.png)
66

@@ -230,7 +230,7 @@ The following way is recommended (cpp-lazy version >= 5.0.1). Note that you choo
230230
231231
include(FetchContent)
232232
FetchContent_Declare(cpp-lazy
233-
URL https://github.com/MarcDirven/cpp-lazy/releases/download/<TAG_HERE E.G. v9.0.0>/cpp-lazy-src.zip
233+
URL https://github.com/Kaaserne/cpp-lazy/releases/download/<TAG_HERE E.G. v9.0.0>/cpp-lazy-src.zip
234234
# Below is optional
235235
# URL_MD5 <MD5 HASH OF cpp-lazy-src.zip>
236236
# If using CMake >= 3.24, preferably set <bool> to TRUE
@@ -249,7 +249,7 @@ An alternative ('less' recommended), add to your `CMakeLists.txt` the following:
249249
250250
include(FetchContent)
251251
FetchContent_Declare(cpp-lazy
252-
GIT_REPOSITORY https://github.com/MarcDirven/cpp-lazy
252+
GIT_REPOSITORY https://github.com/Kaaserne/cpp-lazy
253253
GIT_TAG ... # Commit hash
254254
# If using CMake >= 3.24, preferably set <bool> to TRUE
255255
# DOWNLOAD_EXTRACT_TIMESTAMP <bool>
@@ -311,7 +311,7 @@ int main() {
311311
```
312312

313313
### Using `git clone`
314-
Clone the repository using `git clone https://github.com/MarcDirven/cpp-lazy/` and add to `CMakeLists.txt` the following:
314+
Clone the repository using `git clone https://github.com/Kaaserne/cpp-lazy/` and add to `CMakeLists.txt` the following:
315315
```cmake
316316
add_subdirectory(cpp-lazy)
317317
add_executable(${PROJECT_NAME} main.cpp)
@@ -320,19 +320,6 @@ target_link_libraries(${PROJECT_NAME} cpp-lazy::cpp-lazy)
320320
```
321321

322322
# Benchmarks
323-
The time is equal to one iteration. One iteration includes the creation of the iterable and one iteration of that iterable. Compiled with: gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04).
323+
The time is equal to one iteration. One iteration includes the creation of the iterable and one iteration of that iterable. Compiled with: gcc version 13.3.0.
324324

325-
C++11
326-
![](https://github.com/Kaaserne/cpp-lazy/blob/master/bench/benchmarks-iterators-11.png?raw=true)
327-
328-
C++14
329-
330-
![](https://github.com/Kaaserne/cpp-lazy/blob/master/bench/benchmarks-iterators-14.png?raw=true)
331-
332-
C++17
333-
334-
![](https://github.com/Kaaserne/cpp-lazy/blob/master/bench/benchmarks-iterators-17.png?raw=true)
335-
336-
C++20
337-
338-
![](https://github.com/Kaaserne/cpp-lazy/blob/master/bench/benchmarks-iterators-20.png?raw=true)
325+
<div style="text-align:center"><img src="https://raw.githubusercontent.com/Kaaserne/cpp-lazy/master/bench/benchmarks-iterators-C%2B%2B23.png" /></div>

bench/bar_chart_maker.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,21 @@ def make_chart(cxx_version: str, path: str):
127127

128128

129129
async def main():
130+
cxx_version = None
130131
try:
131132
cxx_version = sys.argv[1]
132133
except IndexError:
133-
print('Usage: python bar_chart_maker.py <cxx_version>')
134-
sys.exit(1)
134+
print('No CXX version provided, using CMakeCache.txt.')
135+
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'build', 'CMakeCache.txt'), 'r') as cmake_cache:
136+
for line in cmake_cache:
137+
if not line.startswith('CMAKE_CXX_STANDARD:'):
138+
continue
139+
cxx_version = line.split('=')[1].strip()
140+
break
141+
if cxx_version is None:
142+
print('No CXX version provided and CMakeCache.txt does not contain CMAKE_CXX_STANDARD.')
143+
sys.exit(1)
144+
print('Found CXX version in CMakeCache.txt:', cxx_version)
135145

136146
make_chart(cxx_version, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'build'))
137147

bench/benchmarks-iterators-11.png

-319 KB
Binary file not shown.

bench/benchmarks-iterators-14.png

-318 KB
Binary file not shown.

bench/benchmarks-iterators-17.png

-322 KB
Binary file not shown.

bench/benchmarks-iterators-20.png

-348 KB
Binary file not shown.

bench/benchmarks-iterators-23.png

2.17 KB
Loading

bench/benchmarks-iterators.cpp

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,23 @@ void chunk_if_lz(benchmark::State& state) {
8080
}
8181
}
8282

83+
#if defined(__cpp_lib_ranges_chunk_by) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 23
84+
85+
void chunk_if_std(benchmark::State& state) {
86+
auto a = lz::range(static_cast<int>(size_policy)) | lz::to<std::array<int, size_policy>>();
87+
constexpr static auto half = static_cast<int>(size_policy / 2);
88+
89+
for (auto _ : state) {
90+
for (auto&& x : std::ranges::chunk_by(a, [](int i) noexcept { return i == half; })) {
91+
for (int y : x) {
92+
benchmark::DoNotOptimize(y);
93+
}
94+
}
95+
}
96+
}
97+
98+
#endif
99+
83100
void chunks_lz(benchmark::State& state) {
84101
auto a = lz::range(static_cast<int>(size_policy)) | lz::to<std::array<int, size_policy>>();
85102
for (auto _ : state) {
@@ -91,6 +108,21 @@ void chunks_lz(benchmark::State& state) {
91108
}
92109
}
93110

111+
#if defined(__cpp_lib_ranges_chunk) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 23
112+
113+
void chunks_std(benchmark::State& state) {
114+
auto a = lz::range(static_cast<int>(size_policy)) | lz::to<std::array<int, size_policy>>();
115+
for (auto _ : state) {
116+
for (auto&& chunk : std::views::chunks(a, 8)) {
117+
for (int x : chunk) {
118+
benchmark::DoNotOptimize(x);
119+
}
120+
}
121+
}
122+
}
123+
124+
#endif
125+
94126
void common_lz(benchmark::State& state) {
95127
auto a = lz::generate([]() noexcept { return 0; }, size_policy);
96128

@@ -480,6 +512,21 @@ void take_every_lz(benchmark::State& state) {
480512
}
481513
}
482514

515+
#if defined(__cpp_lib_ranges_stride) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 23
516+
517+
void take_every_std(benchmark::State& state) {
518+
constexpr size_t offset = 2;
519+
std::array<int, size_policy * offset> array;
520+
521+
for (auto _ : state) {
522+
for (int taken : lz::ranges::stride(array, offset)) {
523+
benchmark::DoNotOptimize(taken);
524+
}
525+
}
526+
}
527+
528+
#endif
529+
483530
void take_while_lz(benchmark::State& state) {
484531
auto array = lz::range(static_cast<int>(size_policy)) | lz::to<std::array<int, size_policy>>();
485532

@@ -657,6 +704,21 @@ void split_multiple_std(benchmark::State& state) {
657704
}
658705
}
659706

707+
#if defined(__cpp_lib_ranges_cartesian_product) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 20
708+
709+
void cartesian_product_std(benchmark::State& state) {
710+
std::array<int, size_policy / 8> a;
711+
std::array<char, size_policy / 4> b;
712+
713+
for (auto _ : state) {
714+
for (auto&& tup : std::views::cartesian_product(a, b)) {
715+
benchmark::DoNotOptimize(tup);
716+
}
717+
}
718+
}
719+
720+
#endif
721+
660722
#if defined(__cpp_lib_ranges_repeat) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 20
661723

662724
void repeat_std(benchmark::State& state) {
@@ -778,6 +840,24 @@ BENCHMARK(zip4_lz);
778840
BENCHMARK(zip3_lz);
779841
BENCHMARK(zip2_lz);
780842

843+
#if defined(__cpp_lib_ranges_cartesian_product) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 23
844+
845+
BENCHMARK(cartesian_product_std);
846+
847+
#endif
848+
849+
#if defined(__cpp_lib_ranges_chunk) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 23
850+
851+
BENCHMARK(chunks_std);
852+
853+
#endif
854+
855+
#if defined(__cpp_lib_ranges_chunk_by) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 23
856+
857+
BENCHMARK(chunk_if_std);
858+
859+
#endif
860+
781861
#if LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 20
782862

783863
BENCHMARK(common_std);
@@ -791,13 +871,19 @@ BENCHMARK(split_multiple_std);
791871

792872
#endif
793873

794-
#if defined(__cpp_lib_ranges_repeat) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 20
874+
#if defined(__cpp_lib_ranges_stride) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 23
875+
876+
BENCHMARK(take_every_std);
877+
878+
#endif
879+
880+
#if defined(__cpp_lib_ranges_repeat) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 23
795881

796882
BENCHMARK(repeat_std);
797883

798884
#endif
799885

800-
#if defined(__cpp_lib_ranges_zip) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 20
886+
#if defined(__cpp_lib_ranges_zip) && LZ_HAS_INCLUDE(<ranges>) && CMAKE_CXX_STANDARD >= 23
801887

802888
BENCHMARK(zip4_std);
803889
BENCHMARK(zip3_std);

0 commit comments

Comments
 (0)