Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [~]-[%] cat vecbench.hpp
- #pragma once
- #include <stddef.h>
- struct Span {
- double *p;
- size_t n;
- };
- void fill_with_zeros(Span *s);
- [~]-[%] cat vecbench.cpp
- #include "vecbench.hpp"
- #include <stddef.h>
- void fill_with_zeros(Span *s)
- {
- for (size_t i = 0; i < s->n; ++i) {
- s->p[i] = 0.0;
- }
- }
- [~]-[%] cat main.cpp
- #include <vector>
- #include "vecbench.hpp"
- int main()
- {
- std::vector<double> v(100 * 1000 * 1000, 1.0);
- Span s = {v.data(), v.size()};
- fill_with_zeros(&s);
- return v[0] == 0.0 ? 0 : 1;
- }
- [~]-[%] g++ -Wall -Wextra -O3 vecbench.cpp main.cpp -o main; time (repeat 10 ./main)
- real 1.38s
- user 0.89s
- sys 0.49s
- [~]-[%] g++ -Wall -Wextra -O3 -fno-strict-aliasing vecbench.cpp main.cpp -o main; time (repeat 10 ./main)
- real 1.93s
- user 1.44s
- sys 0.48s
- [~]-[%] python3
- Python 3.13.12 (main, Feb 4 2026, 15:06:39) [GCC 15.2.0] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- ● >>> 1.93 / 1.38
- 1.3985507246376812
Advertisement