Skip to main content

All Questions

Tagged with
2 votes
1 answer
55 views

Run time depends on code after the measured part

Consider the following C++23 program (online). #include <chrono> #include <cstdio> #include <print> constexpr size_t NWrites = 10000000000; #define DEST_STORAGE static #define ...
Dr. Gut's user avatar
  • 2,693
0 votes
3 answers
87 views

nested switch statements for template arguments

We have some templated function that takes 2 compile-time arguments, e.g. template<int a, int b> void SomeFunc(double *x, double *y, double *z); For performance reasons, it is better to have ...
debronee101's user avatar
0 votes
0 answers
23 views

Enabling Efficiency Mode (EcoQoS) for a Process by PID in C++ and Verifying in Task Manager

I'm trying to enable Efficiency Mode (EcoQoS) for a process given its process ID (PID). I have referred to this similar question on Stack Overflow, but I'm still facing issues. Issue: Although the ...
Shivam's user avatar
  • 52
1 vote
0 answers
50 views

How to Align Memory to Cache Line Using Boost Interprocess Shared Memory

I am writing a Boost.Interprocess code for shared memory between two processes. I am using managed_shared_memory. I'm initializing the memory using boost::interprocess::open_or_create, and I am ...
Rishi Jain's user avatar
1 vote
1 answer
61 views

why the loop order influence the efficiency of code in GEMM?

I'm writing a GEMM code in C++, but the loop order actually influences a lot to the efficiency. Code: // The first edition void gemm_cpu_naive( int* __restrict__ C, const int* __restrict__ A, ...
soyail's user avatar
  • 11
1 vote
1 answer
77 views

Exposing what the compiler does for passing to a reference vs to a const reference

Compiling the code shown below, and examining the disassembly (objdump -DSs a.out > a.dis), I am unable to see any difference in what happens for invoking fun_ref(T &) and fun_const_ref(const T ...
user1823664's user avatar
  • 1,083
1 vote
0 answers
52 views

How to reduce cache miss in SPSC queue pop function?

I am working on optimizing a Single Producer Single Consumer (SPSC) queue in C++. The following is the miniman reproducible example for my implementation: #include <atomic> #include <cstddef&...
Rishi Jain's user avatar
0 votes
2 answers
170 views

Are bitwise operators slower than common loops like a for loop?

Do bitwise operators like & (AND) take more runtime than common for loops? Today I was doing a power of 2 question in LeetCode. My code was this: if (n > 0 && (n & (n - 1)) == 0) { ...
XD XD's user avatar
  • 27
0 votes
0 answers
46 views

How to performantly submit messages of arbitrary size (and fields) to a common interface?

I have a message processing interface that accepts messages of different types. What I have now goes along the lines of this: Demo #include <iostream> enum class MsgType { write, read, ...
glades's user avatar
  • 4,435
0 votes
0 answers
77 views

How to properly read over TCP when size is not known?

I've always used "over TCP" protocols with a fixed and known size. But what about reading data without a known size where the 'end' is marked by a delimiter? (e.g HTTP Headers) This is the ...
Jozese's user avatar
  • 33
1 vote
1 answer
61 views

Low Latency Communication in C++: Raw Sockets with io_uring vs. ZeroMQ, NanoMQ, Aeron etc [closed]

I have two C++ services that need ultra low-latency communication over the network. I'm considering using raw sockets with io_uring but also looking at possibilities of using various messaging queues ...
works's user avatar
  • 85
1 vote
0 answers
118 views

Why doesn't this SIMD code show better performance?

I wrote a simple code to test the performance and set my data: #include <iostream> #include <ctime> #include <smmintrin.h> #include <immintrin.h> unsigned t0, t1; struct VAL ...
Gonzalo Vasquez's user avatar
-2 votes
2 answers
114 views

Possible Improvements to sum(int n) function or calling code in C++

I have a function that calculates sum of the numbers up to a number N and returns it back to calling code as follows: long sumUpToNumber(int n){ long sum; return sum = n * (n + 1) / 2; } int ...
DannyBoy's user avatar
2 votes
1 answer
213 views

Is bitwise shift more "efficient" than a for loop? [closed]

I just started going through "Data Structures and Algorithms in C++" and in one of the intro exercises they ask to write a function which returns powers of 2 and takes the exponent n as an ...
bridgeToRail's user avatar
5 votes
3 answers
397 views

The most efficient way to test if a positive integer is 2^n (i.e. 1, 2, 4, 8, etc.) in C++20?

A handy method to verify if a positive integer n is a power of two (like 1, 2, 4, 8, etc.) is to use the following test for having no more than 1 bit set: bool test = n & (n - 1) == 0; This ...
Amit's user avatar
  • 1,119

15 30 50 per page
1
2 3 4 5
401