Container System 0.1.0
High-performance C++20 type-safe container framework with SIMD-accelerated serialization
Loading...
Searching...
No Matches
simd_batch_example.cpp
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
13
14#include <kcenon/container/simd_batch.h>
15
16#include <chrono>
17#include <cstdint>
18#include <iostream>
19
20using namespace kcenon::container;
21
22int main()
23{
24 std::cout << "=== SIMD Batch Example ===" << std::endl;
25
26 // 1. Basic batch operations with integers
27 std::cout << "\n1. Integer batch:" << std::endl;
28 core::simd_batch<int32_t> int_batch;
29
30 for (int32_t i = 0; i < 100; ++i)
31 {
32 int_batch.push(i * i);
33 }
34
35 std::cout << " Size: " << int_batch.size() << std::endl;
36
37 const auto& values = int_batch.values();
38 std::cout << " First 5: ";
39 for (size_t i = 0; i < 5 && i < values.size(); ++i)
40 {
41 std::cout << values[i] << " ";
42 }
43 std::cout << std::endl;
44
45 // 2. Double-precision batch
46 std::cout << "\n2. Double batch:" << std::endl;
47 core::simd_batch<double> double_batch;
48
49 for (int i = 0; i < 50; ++i)
50 {
51 double_batch.push(i * 0.1);
52 }
53 std::cout << " Size: " << double_batch.size() << std::endl;
54
55 // 3. Performance measurement
56 std::cout << "\n3. Batch insert performance:" << std::endl;
57 core::simd_batch<int64_t> perf_batch;
58
59 auto start = std::chrono::high_resolution_clock::now();
60 for (int64_t i = 0; i < 100000; ++i)
61 {
62 perf_batch.push(i);
63 }
64 auto end = std::chrono::high_resolution_clock::now();
65 auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
66
67 std::cout << " 100K inserts: " << us << " us" << std::endl;
68 std::cout << " Final size: " << perf_batch.size() << std::endl;
69
70 // 4. Clear and reuse
71 perf_batch.clear();
72 std::cout << "\n4. After clear: size=" << perf_batch.size() << std::endl;
73
74 std::cout << "\nDone." << std::endl;
75 return 0;
76}
int main()