4 ms·
What version of GCC are you using? For me both versions perform the same, both on Ubuntu and Windows: $ time ./lone 1000 1 851000 real
by BoppreH 3y ago
What version of GCC are you using? For me both versions perform the same, both on Ubuntu and Windows:
$ time ./lone 1000 1
851000
real 0m3.578s
user 0m3.574s
sys 0m0.004s
$ time ./ltwo 1000 1
851000
real 0m3.583s
user 0m3.583s
sys 0m0.000s
$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- torstenvl 3y agoSorry, I write 'gcc' purely out of force of habit. I'm using Clang/LLVM. [17:23:00 user@boxer ~/looptest] $ uname -a Darwin boxer.local 21.6.0 Darwin Kernel Version 21.6.0: Thu Jun 8 23:57:12 PDT 2023; root:xnu-8020.240.18.701.6~1/RELEASE_X86_64 x86_64 [17:23:47 user@boxer ~/looptest] $ cc -v Apple clang version 14.0.0 (clang-1400.0.29.202) Target: x86_64-apple-darwin21.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin Clang generates the sete instruction for me with the above code: [17:23:49 user@boxer ~/looptest] $ gcc -c -O3 loop2.c [17:25:00 user@boxer ~/looptest] $ objdump -d --symbolize-operands --x86-asm-syntax=intel --no-show-raw-insn loop2.o loop2.o: file format mach-o 64-bit x86-64 Disassembly of section __TEXT,__text: 0000000000000000 <_run_switches>: 0: push rbp 1: mov rbp, rsp 4: xor eax, eax 6: nop word ptr cs:[rax + rax] <L0>: 10: movzx ecx, byte ptr [rdi] 13: add rdi, 1 17: xor edx, edx 19: cmp cl, 115 1c: sete dl 1f: add eax, edx 21: xor edx, edx 23: cmp cl, 112 26: sete dl 29: sub eax, edx 2b: test cl, cl 2d: jne <L0> 2f: pop rbp 30: ret