v2 / vlib / v / tests / bench / val_vs_ptr.c
21 lines · 17 sloc · 271 bytes · eed7c91e87468179b8c074fd68a56ace1f6093f6
Raw
1#include <stdio.h>
2
3int increment_val(int n) {
4 return n + 2;
5}
6
7// ~26% faster
8void increment_ptr(int* n) {
9 *n += 2;
10}
11
12int main() {
13 int n = 0;
14 for (int i = 0; i < 1000000000; i++) {
15 n = increment_val(n);
16 //increment_ptr(&n);
17 }
18 printf("%d\n", n);
19 return 0;
20}
21
22