2017年12月18日 星期一

C++ Pass by Pointer vs Pass by value vs Pass by Reference

#include <iostream>
#include <time.h>

void function1(int *ptr) { // pass by pointer
*ptr *= 5;
}

void function2(int val) { // pass by value
val *= 5;
}

void function3(int& ref) { // pass by reference
ref *= 5;
}

int main() {
int nmbr = 5;
clock_t start = clock();
for (long i = 0; i < 1000 * 1000 * 1000; ++i) {
function1(&nmbr);
//function2(nmbr);
//function3(nmbr);
}
clock_t stop = clock();
std::cout << "time: " << stop - start;
return 0;
}

2025-03-29 Debian 12 Promox 8.3.5 IOMMU

  # reference https://cloud.tencent.com/developer/article/2414840 # before root@box02:~# dmesg | grep -E "DMAR|IOMMU" echo nothing...