You are not logged in.
I run Arch on my laptop and Ubuntu on my desktop (Intel i7 on both). The corresponding gcc versions are 11.2.0 and 7.5.0. The optimization for speed flags (-O0, -O1, -O2, -O3, -Ofast) seem to work under Ubuntu but they make no difference under Arch. For instance (program: coin.c):
/* coin.c */
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define COIN_MAX 10000000
void coin(unsigned int ntrials)
{
unsigned int R2 = RAND_MAX/2;
unsigned int tail=0;
usigned int temp;
double result;
srand(1750);
for (unsigned int s = 0; s < ntrials; s++){
temp = rand();
tail = temp > R2 ? tail : tail+1;
}
result = 100.0*((double) tail)/ntrials;
printf("Percentage of tails from %u tosses: %.2f\n", ntrials, result);
}
int main(void)
{
clock_t start_time, end_time;
start_time = clock();
for (unsigned int j = 10; j <= COIN_MAX; j *= 10){
coin(j);
}
end_time = clock();
printf("EXECUTION TIME: %.2f seconds\n",
((double)(end_time-start_time))/(CLOCKS_PER_SEC));
printf("EXECUTION TIME: %.2f minutes\n",
((double)(end_time-start_time))/(60*CLOCKS_PER_SEC));
return 0;
}The execution times I get under Arch are pretty much the same regardless of the optimization flag used (about 0.20 second). Under Ubuntu, however, they vary quite a bit (from approx. 0.08 second with -O3 to 0.14 second with -O0).
Suggestions are welcome. Thank you.
EDIT: Added missing #include<stdlib.h>
Last edited by cribari (2022-04-05 20:35:31)
Linux, street photography and Baroque music enthusiast.
Offline
Offline
Exactly the same CPU in both systems?
No. My laptop (Arch):
cribari@darwin7 ~ $ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
microcode : 0xec
cpu MHz : 2000.000
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple pml ept_mode_based_exec
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 3999.93
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
microcode : 0xec
cpu MHz : 2000.000
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 1
cpu cores : 4
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple pml ept_mode_based_exec
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 3999.93
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
microcode : 0xec
cpu MHz : 2000.000
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 2
cpu cores : 4
apicid : 4
initial apicid : 4
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple pml ept_mode_based_exec
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 3999.93
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
microcode : 0xec
cpu MHz : 2000.000
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
apicid : 6
initial apicid : 6
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple pml ept_mode_based_exec
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 3999.93
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 4
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
microcode : 0xec
cpu MHz : 1126.561
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple pml ept_mode_based_exec
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 3999.93
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 5
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
microcode : 0xec
cpu MHz : 2000.000
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 1
cpu cores : 4
apicid : 3
initial apicid : 3
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple pml ept_mode_based_exec
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 3999.93
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 6
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
microcode : 0xec
cpu MHz : 2000.000
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 2
cpu cores : 4
apicid : 5
initial apicid : 5
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple pml ept_mode_based_exec
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 3999.93
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 7
vendor_id : GenuineIntel
cpu family : 6
model : 142
model name : Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
stepping : 10
microcode : 0xec
cpu MHz : 2000.000
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
apicid : 7
initial apicid : 7
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities
vmx flags : vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple pml ept_mode_based_exec
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 3999.93
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:My desktop (Ubuntu):
cribari@edgeworth:~$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
stepping : 3
microcode : 0x28
cpu MHz : 1297.715
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 5986.20
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
stepping : 3
microcode : 0x28
cpu MHz : 1297.790
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 1
cpu cores : 4
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 5986.20
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
stepping : 3
microcode : 0x28
cpu MHz : 1297.116
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 2
cpu cores : 4
apicid : 4
initial apicid : 4
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 5986.20
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
stepping : 3
microcode : 0x28
cpu MHz : 1297.006
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
apicid : 6
initial apicid : 6
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 5986.20
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 4
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
stepping : 3
microcode : 0x28
cpu MHz : 1295.750
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 5986.20
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 5
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
stepping : 3
microcode : 0x28
cpu MHz : 1299.762
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 1
cpu cores : 4
apicid : 3
initial apicid : 3
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 5986.20
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 6
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
stepping : 3
microcode : 0x28
cpu MHz : 1297.678
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 2
cpu cores : 4
apicid : 5
initial apicid : 5
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 5986.20
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:
processor : 7
vendor_id : GenuineIntel
cpu family : 6
model : 60
model name : Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
stepping : 3
microcode : 0x28
cpu MHz : 1297.029
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
apicid : 7
initial apicid : 7
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds
bogomips : 5986.20
clflush size : 64
cache_alignment : 64
address sizes : 39 bits physical, 48 bits virtual
power management:Linux, street photography and Baroque music enthusiast.
Offline
Arch:
cribari@darwin7 ~ $ gcc -O0 -o coin coin.c
cribari@darwin7 ~ $ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.22 seconds
EXECUTION TIME: 0.00 minutes
cribari@darwin7 ~ $ gcc -O1 -o coin coin.c
cribari@darwin7 ~ $ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.22 seconds
EXECUTION TIME: 0.00 minutes
cribari@darwin7 ~ $ gcc -O2 -o coin coin.c
cribari@darwin7 ~ $ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.22 seconds
EXECUTION TIME: 0.00 minutes
cribari@darwin7 ~ $ gcc -O3 -o coin coin.c
cribari@darwin7 ~ $ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.22 seconds
EXECUTION TIME: 0.00 minutes
cribari@darwin7 ~ $ gcc -Ofast -o coin coin.c
cribari@darwin7 ~ $ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.22 seconds
EXECUTION TIME: 0.00 minutesUbuntu:
bari@edgeworth:~$ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.14 seconds
EXECUTION TIME: 0.00 minutes
cribari@edgeworth:~$ gcc -O1 -o coin coin.c
cribari@edgeworth:~$ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.09 seconds
EXECUTION TIME: 0.00 minutes
cribari@edgeworth:~$ gcc -O2 -o coin coin.c
cribari@edgeworth:~$ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.08 seconds
EXECUTION TIME: 0.00 minutes
cribari@edgeworth:~$ gcc -O3 -o coin coin.c
cribari@edgeworth:~$ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.08 seconds
EXECUTION TIME: 0.00 minutes
cribari@edgeworth:~$ gcc -Ofast -o coin coin.c
cribari@edgeworth:~$ ./coin
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.08 seconds
EXECUTION TIME: 0.00 minutes
cribari@edgeworth:~$ Linux, street photography and Baroque music enthusiast.
Offline
Try it with different output filenames for each build.
Offline
Try it with different output filenames for each build.
Arch:
cribari@darwin7 ~ $ gcc -O0 -o coin0 coin.c
cribari@darwin7 ~ $ ./coin0
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.19 seconds
EXECUTION TIME: 0.00 minutes
cribari@darwin7 ~ $ gcc -O1 -o coin1 coin.c
cribari@darwin7 ~ $ ./coin1
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.18 seconds
EXECUTION TIME: 0.00 minutes
cribari@darwin7 ~ $ gcc -O2 -o coin2 coin.c
cribari@darwin7 ~ $ ./coin2
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.18 seconds
EXECUTION TIME: 0.00 minutes
cribari@darwin7 ~ $ gcc -O3 -o coin3 coin.c
cribari@darwin7 ~ $ ./coin3
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.18 seconds
EXECUTION TIME: 0.00 minutes
cribari@darwin7 ~ $ Linux, street photography and Baroque music enthusiast.
Offline
gcc -O3 coin.c
coin.c: In function ‘coin’:
coin.c:10:21: error: ‘RAND_MAX’ undeclared (first use in this function)
10 | unsigned int R2 = RAND_MAX/2;
| ^~~~~~~~
coin.c:10:21: note: each undeclared identifier is reported only once for each function it appears in
coin.c:15:3: warning: implicit declaration of function ‘srand’ [-Wimplicit-function-declaration]
15 | srand(1750);
| ^~~~~
coin.c:18:14: warning: implicit declaration of function ‘rand’ [-Wimplicit-function-declaration]
18 | temp = rand();Adding in stdlib
gcc -O3 coin.c
$ ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.05 seconds
EXECUTION TIME: 0.00 minutes
gcc -O0 coin.c
$ ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.11 seconds
EXECUTION TIME: 0.00 minutesEdit:
The output of the following might help
type -a gcc
gcc -O0 -v coin.c
gcc -O0 --S o coin0.S coin.c
gcc -O3 -S -o coin3.S coin.c
diff coin0.S coin3.SLast edited by loqs (2022-04-05 15:26:44)
Offline
The output of the following might help
type -a gcc gcc -O0 -v coin.c gcc -O0 --S o coin0.S coin.c gcc -O3 -S -o coin3.S coin.c diff coin0.S coin3.S
Here it is:
cribari@darwin7 ~ $ type -a gcc
gcc is /usr/lib/ccache/bin/gcc
gcc is /usr/bin/gcc
cribari@darwin7 ~ $ gcc -O0 -v coin.c
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror --with-build-config=bootstrap-lto --enable-link-serialization=1 gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
COLLECT_GCC_OPTIONS='-O0' '-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/cc1 -quiet -v coin.c -quiet -dumpdir a- -dumpbase coin.c -dumpbase-ext .c -mtune=generic -march=x86-64 -O0 -version -o /tmp/cc1GEVwG.s
GNU C17 (GCC) version 11.2.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.24-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include
/usr/local/include
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/include-fixed
/usr/include
End of search list.
GNU C17 (GCC) version 11.2.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version isl-0.24-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 65a5ec6b673b24273c0fdde359680a16
COLLECT_GCC_OPTIONS='-O0' '-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a-'
as -v --64 -o /tmp/ccbftIY7.o /tmp/cc1GEVwG.s
GNU assembler version 2.38 (x86_64-pc-linux-gnu) using BFD version (GNU Binutils) 2.38
COMPILER_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-O0' '-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/collect2 -plugin /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccQ0xA7Z.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib/Scrt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/crtbeginS.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0 -L/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../.. /tmp/ccbftIY7.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib/crtn.o
COLLECT_GCC_OPTIONS='-O0' '-v' '-mtune=generic' '-march=x86-64' '-dumpdir' 'a.'
cribari@darwin7 ~ $ gcc -O0 --S o coin0.S coin.c
gcc: error: unrecognized command-line option ‘--S’; did you mean ‘-S’?
cribari@darwin7 ~ $ gcc -O0 -S -o coin0.S coin.c
cribari@darwin7 ~ $ gcc -O3 -S -o coin3.S coin.c
cribari@darwin7 ~ $ diff coin0.S coin3.S
3c3
< .section .rodata
---
> .section .rodata.str1.8,"aMS",@progbits,1
5c5
< .LC1:
---
> .LC2:
7a8
> .p2align 4
11c12
< .LFB6:
---
> .LFB22:
13c14
< pushq %rbp
---
> pushq %r12
15,21c16,17
< .cfi_offset 6, -16
< movq %rsp, %rbp
< .cfi_def_cfa_register 6
< subq $48, %rsp
< movl %edi, -36(%rbp)
< movl $1073741823, -16(%rbp)
< movl $0, -24(%rbp)
---
> .cfi_offset 12, -16
> movl %edi, %r12d
22a19,24
> pushq %rbp
> .cfi_def_cfa_offset 24
> .cfi_offset 6, -24
> pushq %rbx
> .cfi_def_cfa_offset 32
> .cfi_offset 3, -32
24,36c26,31
< movl $0, -20(%rbp)
< jmp .L2
< .L5:
< call rand@PLT
< movl %eax, -12(%rbp)
< movl -12(%rbp), %eax
< cmpl %eax, -16(%rbp)
< jb .L3
< movl -24(%rbp), %eax
< addl $1, %eax
< jmp .L4
< .L3:
< movl -24(%rbp), %eax
---
> testl %r12d, %r12d
> je .L9
> xorl %ebx, %ebx
> xorl %ebp, %ebp
> .p2align 4,,10
> .p2align 3
38,71c33,38
< movl %eax, -24(%rbp)
< addl $1, -20(%rbp)
< .L2:
< movl -20(%rbp), %eax
< cmpl -36(%rbp), %eax
< jb .L5
< movl -24(%rbp), %eax
< testq %rax, %rax
< js .L6
< pxor %xmm0, %xmm0
< cvtsi2sdq %rax, %xmm0
< jmp .L7
< .L6:
< movq %rax, %rdx
< shrq %rdx
< andl $1, %eax
< orq %rax, %rdx
< pxor %xmm0, %xmm0
< cvtsi2sdq %rdx, %xmm0
< addsd %xmm0, %xmm0
< .L7:
< movsd .LC0(%rip), %xmm1
< mulsd %xmm0, %xmm1
< movl -36(%rbp), %eax
< testq %rax, %rax
< js .L8
< pxor %xmm0, %xmm0
< cvtsi2sdq %rax, %xmm0
< jmp .L9
< .L8:
< movq %rax, %rdx
< shrq %rdx
< andl $1, %eax
< orq %rax, %rdx
---
> call rand@PLT
> cmpl $1073741824, %eax
> adcl $0, %ebp
> addl $1, %ebx
> cmpl %ebx, %r12d
> jne .L4
73,83c40,51
< cvtsi2sdq %rdx, %xmm0
< addsd %xmm0, %xmm0
< .L9:
< divsd %xmm0, %xmm1
< movsd %xmm1, -8(%rbp)
< movq -8(%rbp), %rdx
< movl -36(%rbp), %eax
< movq %rdx, %xmm0
< movl %eax, %esi
< leaq .LC1(%rip), %rax
< movq %rax, %rdi
---
> cvtsi2sdq %rbp, %xmm0
> mulsd .LC1(%rip), %xmm0
> .L2:
> movl %r12d, %eax
> pxor %xmm1, %xmm1
> popq %rbx
> .cfi_remember_state
> .cfi_def_cfa_offset 24
> movl %r12d, %esi
> cvtsi2sdq %rax, %xmm1
> popq %rbp
> .cfi_def_cfa_offset 16
85,89c53,63
< call printf@PLT
< nop
< leave
< .cfi_def_cfa 7, 8
< ret
---
> popq %r12
> .cfi_def_cfa_offset 8
> leaq .LC2(%rip), %rdi
> divsd %xmm1, %xmm0
> jmp printf@PLT
> .p2align 4,,10
> .p2align 3
> .L9:
> .cfi_restore_state
> pxor %xmm0, %xmm0
> jmp .L2
91c65
< .LFE6:
---
> .LFE22:
93,94c67,68
< .section .rodata
< .LC3:
---
> .section .rodata.str1.1,"aMS",@progbits,1
> .LC4:
96c70
< .LC5:
---
> .LC6:
98c72,73
< .text
---
> .section .text.startup,"ax",@progbits
> .p2align 4
102c77
< .LFB7:
---
> .LFB23:
104c79
< pushq %rbp
---
> pushq %r15
106,126c81,101
< .cfi_offset 6, -16
< movq %rsp, %rbp
< .cfi_def_cfa_register 6
< subq $32, %rsp
< call clock@PLT
< movq %rax, -16(%rbp)
< movl $10, -20(%rbp)
< jmp .L11
< .L12:
< movl -20(%rbp), %eax
< movl %eax, %edi
< call coin
< movl -20(%rbp), %edx
< movl %edx, %eax
< sall $2, %eax
< addl %edx, %eax
< addl %eax, %eax
< movl %eax, -20(%rbp)
< .L11:
< cmpl $10000000, -20(%rbp)
< jbe .L12
---
> .cfi_offset 15, -16
> pushq %r14
> .cfi_def_cfa_offset 24
> .cfi_offset 14, -24
> pushq %r13
> .cfi_def_cfa_offset 32
> .cfi_offset 13, -32
> leaq .LC2(%rip), %r13
> pushq %r12
> .cfi_def_cfa_offset 40
> .cfi_offset 12, -40
> movl $7, %r12d
> pushq %rbp
> .cfi_def_cfa_offset 48
> .cfi_offset 6, -48
> movl $10, %ebp
> pushq %rbx
> .cfi_def_cfa_offset 56
> .cfi_offset 3, -56
> subq $24, %rsp
> .cfi_def_cfa_offset 80
128,133c103,129
< movq %rax, -8(%rbp)
< movq -8(%rbp), %rax
< subq -16(%rbp), %rax
< pxor %xmm0, %xmm0
< cvtsi2sdq %rax, %xmm0
< movsd .LC2(%rip), %xmm1
---
> movq %rax, %r14
> .p2align 4,,10
> .p2align 3
> .L18:
> movl $1750, %edi
> xorl %r15d, %r15d
> xorl %ebx, %ebx
> call srand@PLT
> .p2align 4,,10
> .p2align 3
> .L15:
> call rand@PLT
> cmpl $1073741824, %eax
> adcl $0, %ebx
> addl $1, %r15d
> cmpl %ebp, %r15d
> jne .L15
> pxor %xmm0, %xmm0
> pxor %xmm1, %xmm1
> movl %r15d, %esi
> movq %r13, %rdi
> cvtsi2sdq %rbx, %xmm0
> mulsd .LC1(%rip), %xmm0
> movl $1, %eax
> cvtsi2sdl %r15d, %xmm1
> leal (%r15,%r15,4), %ebp
> addl %ebp, %ebp
135,138c131,138
< movq %xmm0, %rax
< movq %rax, %xmm0
< leaq .LC3(%rip), %rax
< movq %rax, %rdi
---
> call printf@PLT
> subl $1, %r12d
> jne .L18
> call clock@PLT
> pxor %xmm1, %xmm1
> leaq .LC4(%rip), %rdi
> subq %r14, %rax
> cvtsi2sdq %rax, %xmm1
139a140,142
> movapd %xmm1, %xmm0
> movsd %xmm1, 8(%rsp)
> divsd .LC3(%rip), %xmm0
141,150c144
< movq -8(%rbp), %rax
< subq -16(%rbp), %rax
< pxor %xmm0, %xmm0
< cvtsi2sdq %rax, %xmm0
< movsd .LC4(%rip), %xmm1
< divsd %xmm1, %xmm0
< movq %xmm0, %rax
< movq %rax, %xmm0
< leaq .LC5(%rip), %rax
< movq %rax, %rdi
---
> movsd 8(%rsp), %xmm1
151a146,148
> divsd .LC5(%rip), %xmm1
> leaq .LC6(%rip), %rdi
> movapd %xmm1, %xmm0
153,155c150,164
< movl $0, %eax
< leave
< .cfi_def_cfa 7, 8
---
> addq $24, %rsp
> .cfi_def_cfa_offset 56
> xorl %eax, %eax
> popq %rbx
> .cfi_def_cfa_offset 48
> popq %rbp
> .cfi_def_cfa_offset 40
> popq %r12
> .cfi_def_cfa_offset 32
> popq %r13
> .cfi_def_cfa_offset 24
> popq %r14
> .cfi_def_cfa_offset 16
> popq %r15
> .cfi_def_cfa_offset 8
158c167
< .LFE7:
---
> .LFE23:
160c169
< .section .rodata
---
> .section .rodata.cst8,"aM",@progbits,8
162c171
< .LC0:
---
> .LC1:
166c175
< .LC2:
---
> .LC3:
170c179
< .LC4:
---
> .LC5:
cribari@darwin7 ~ $ Linux, street photography and Baroque music enthusiast.
Offline
So you're using ccache. "Compiler cache that speeds up recompilation by caching previous compilations"
Offline
/usr/lib/ccache/bin/gccccache would be a suspect if not for the later outputs showing gcc produces different assembler at different optimization levels.
The question remains why that is not translating into different timings for you.
Edit:
If you invoke /usr/bin/gcc to avoid ccache any difference?
Last edited by loqs (2022-04-05 15:46:44)
Offline
So you're using ccache. "Compiler cache that speeds up recompilation by caching previous compilations"
I removed ccache from my system, but the problem persisted. Suggestions are welcome.
Linux, street photography and Baroque music enthusiast.
Offline
/usr/lib/ccache/bin/gccccache would be a suspect if not for the later outputs showing gcc produces different assembler at different optimization levels.
The question remains why that is not translating into different timings for you.
Edit:
If you invoke /usr/bin/gcc to avoid ccache any difference?
Unfortunately, not.
Linux, street photography and Baroque music enthusiast.
Offline
I have a backup laptop that runs Arch. The problem also happens there.
I have a second backup laptop (an older machine) that runs Manjaro. I hadn't updated it for a while. I compiled and executed the C program in it using different optimization flags. gcc version was 11.1.0. The optimization flags worked as expected. I then updated all packages and gcc was updated to version 11.2.0. I rebooted, compiled the C program with different optimization flags, and such flags no longer worked as expected; see below. Somehow, the issue must be related to gcc version 11.2.
[cribari@darwin4 ~]$ gcc --version
gcc (GCC) 11.1.0
Copyright (C) 2021 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.
[cribari@darwin4 ~]$ gcc -O3 coin.c
[cribari@darwin4 ~]$ ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.09 seconds
EXECUTION TIME: 0.00 minutes
[cribari@darwin4 ~]$ gcc -O0 coin.c
[cribari@darwin4 ~]$ ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.16 seconds
EXECUTION TIME: 0.00 minutes
[cribari@darwin4 ~]$
[cribari@darwin4 ~]$ gcc --version
gcc (GCC) 11.2.0
Copyright (C) 2021 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.
[cribari@darwin4 ~]$ gcc -O3 coin.c
[cribari@darwin4 ~]$ ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.22 seconds
EXECUTION TIME: 0.00 minutes
[cribari@darwin4 ~]$ gcc -O0 coin.c
[cribari@darwin4 ~]$ ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.22 seconds
EXECUTION TIME: 0.00 minutes
[cribari@darwin4 ~]$ Linux, street photography and Baroque music enthusiast.
Offline
I am not a programmer.
You omitted from this the most important C base library - glibc (its various versions, archlinux, manjaro, ubuntu).
Especially those functions that are the main duty of this program.
78.08% coin libc.so.6 [.] random
3.44% coin libc.so.6 [.] rand
12.50% coin libc.so.6 [.] random_rPerf will tell you the truth.
Certainly the version compiled with -O0 will follow many more instructions than the version -O2.
perf stat --repeat 10 -e instructions,cycles,cpu-clock --sync ./coin_O0
perf stat --repeat 10 -e instructions,cycles,cpu-clock --sync ./coin_O2Alternatively, build a static version. Test it on different systems. From ububtu under archlinux and vice versa.
Maybe the programmer will explain it much more clearly.
Offline
I ran the code with both -O0 and -O3 a number of times and got results that vary by as much as 40%. My conclusion is that the sample size is too small and the test is overwhelmed by the noise of the system (because no system is actually idle).
When I add an extra zero on COIN_MAX, I see about a 10% increase for -O3.
There's another thing I noticed too. Arch with gcc 11.2.0 and Gentoo with gcc 11.2.1 both show about 10% speed up while Debian with gcc 10.2.1 shows a large speed up of as much as 30% in both a virtual machine and on a Raspberry Pi. I'm not sure what's going on there but I suspect improvements gcc and/or glibc.
I also noted that your code rounds the result to %.2f which can round away the 10% increase on such a small sample.
My suggestion is to try it again with
#define COIN_MAX 100000000There can also be a difference in chips so this was tested on AMD 3900xt and RPI 4B.
Offline
I ran the code with both -O0 and -O3 a number of times and got results that vary by as much as 40%. My conclusion is that the sample size is too small and the test is overwhelmed by the noise of the system (because no system is actually idle).
When I add an extra zero on COIN_MAX, I see about a 10% increase for -O3.
There's another thing I noticed too. Arch with gcc 11.2.0 and Gentoo with gcc 11.2.1 both show about 10% speed up while Debian with gcc 10.2.1 shows a large speed up of as much as 30% in both a virtual machine and on a Raspberry Pi. I'm not sure what's going on there but I suspect improvements gcc and/or glibc.
I also noted that your code rounds the result to %.2f which can round away the 10% increase on such a small sample.
My suggestion is to try it again with
#define COIN_MAX 100000000There can also be a difference in chips so this was tested on AMD 3900xt and RPI 4B.
1) Up to gcc 11.1 this code ran in 0.08 second on my Arch laptop when compiled with -O3. 2) As per your suggestion, I added an extra zero to COIN_MAX; the results are below. No major change.
cribari@darwin7 ~ $ gcc --version
gcc (GCC) 11.2.0
Copyright (C) 2021 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.
cribari@darwin7 ~ $ gcc -O0 coin.c && ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
Percentage of tails from 100000000 tosses: 50.00
EXECUTION TIME: 1.68 seconds
EXECUTION TIME: 0.03 minutes
cribari@darwin7 ~ $ gcc -O3 coin.c && ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
Percentage of tails from 100000000 tosses: 50.00
EXECUTION TIME: 1.65 seconds
EXECUTION TIME: 0.03 minutesLinux, street photography and Baroque music enthusiast.
Offline
You omitted from this the most important C base library - glibc (its various versions, archlinux, manjaro, ubuntu).
Here is what I have:
cribari@darwin7 ~ $ pacman -Qi glibc
Name : glibc
Version : 2.35-3
Description : GNU C Library
Architecture : x86_64
URL : https://www.gnu.org/software/libc
Licenses : GPL LGPL
Groups : None
Provides : None
Depends On : linux-api-headers>=4.10 tzdata filesystem
Optional Deps : gd: for memusagestat [installed]
perl: for mtrace [installed]
Required By : a52dec acpi alsa-lib alsa-plugins alsa-utils argon2
attr audacity audit babl base bash bind binutils
bison bluez-libs brotli btrfs-progs bubblewrap bzip2
c-ares cabextract ccache cdparanoia ceph-libs
chromaprint confuse coreutils cracklib dav1d
debuginfod device-mapper diffutils ding-libs discount
dmidecode dosfstools dotconf efibootmgr efivar
elfutils enscript ethtool exfatprogs expat faac
faad2 fakeroot fftw file findutils flex fluidsynth
fribidi fuse2 fuse3 gavl gawk gcc-libs gdb gdbm
giflib gnupg grep gsl gsm gvim gzip haveged hdparm
hiredis hspell http-parser hwloc hyphen ijs
iniparser iproute2 jack2 jansson jasper jdk-openjdk
jdk11-openjdk jemalloc jpegoptim jre-openjdk
jre-openjdk-headless jre11-openjdk
jre11-openjdk-headless json-c kbd keyutils kmod krb5
l-smash ladspa less libaec libao libass libassuan
libasyncns libatomic_ops libavif libavtp libbsd
libburn libcap libcap-ng libcbor libcddb libdatrie
libdmtx libdvbpsi libdvdcss libdvdread libebur128
libedit libepoxy libevdev libexif libexttextcat
libffi libfido2 libfreeaptx libfreexl libgit2
libgpg-error libical libice libid3tag libidn libinih
libinstpatch libjpeg-turbo libkate libksba libldac
liblouis libltc libmad libmaxminddb libmd libmicrodns
libmms libmnl libmpcdec libmpeg2 libmypaint libndp
libnet libnfnetlink libnghttp2 libnl libnsl libogg
libomxil-bellagio libopenmpt libp11-kit libpcap
libpciaccess libpgm libpipeline libplacebo libraw1394
libsamplerate libseccomp libsigsegv libsndfile
libsodium libstemmer libsynctex libtasn1 libtiff
libtommath libtool libunistring libupnp liburing
libusb libutempter libuv libvisual libxau libxcrypt
libxcvt libxdmcp libxshmfence lilv lmdb lpsolve lsof
lz4 lzo m4 make mbedtls md4c mdadm metis
mkinitcpio-busybox mlocate mpfr mtdev mtools ncurses
npth nspr nss-mdns numactl oath-toolkit ocl-icd
opencore-amr openmp openmpi openssh openssl
opera-ffmpeg-codecs optipng opus orc ostree packer
pacman pam patch pciutils perl pinentry pixman
pkgconf popt portaudio portsmf ppp procps-ng
protobuf psutils raptor rasqal rav1e readline rhash
rnnoise rpcsvc-proto rtmpdump run-parts sane sbc sdl
sdl2 sed serd sg3_utils shaderc snappy socat sord
speexdsp sratom sudo suil svt-av1 sysfsutils
systemd-libs talloc tar tdb traceroute tslib twolame
usbutils vamp-plugin-sdk vid.stab vivaldi-ffmpeg-codecs
vulkan-icd-loader wavemon wavpack wayland wget which
xapian-core xorg-bdftopcf xvidcore xxhash yaml-cpp
zimg zita-alsa-pcmi zita-resampler zlib zstd
Optional For : None
Conflicts With : None
Replaces : None
Installed Size : 47.76 MiB
Packager : Frederik Schwan <freswa@archlinux.org>
Build Date : Sun 20 Mar 2022 05:45:03 PM -03
Install Date : Wed 23 Mar 2022 08:36:15 AM -03
Install Reason : Installed as a dependency for another package
Install Script : Yes
Validated By : SignatureLinux, street photography and Baroque music enthusiast.
Offline
@cribari
I tested this code under Archlinux with the following compilers.
gcc (GCC) 4.9.4
gcc (GCC) 9.3.1 20210319
gcc (GCC) 11.2.0 (default Archlinux)
gcc (GCC) 11.2.1 20211030
gcc (GCC) 12.0.1 20220220 (experimental)
Under my cpu there is no difference in the output of this program (different optimizations -O0 and -O2).
The differences between -O0 and -O2, measured with perf, are distinct.
In the case of my CPU. 94% of the functions during the execution of this program are in libc.so.6 (random, rand, random_r). As I guess, the compiler doesn't optimize them, because they come with glibc from Archlinux repository.
perf record -e cycles:pp --call-graph dwarf ./coin
perf reportLast edited by latalante1 (2022-04-05 22:13:04)
Offline
Alternatively, build a static version. Test it on different systems. From ububtu under archlinux and vice versa.
Off topic but in theory with a static version the compiler could optimize through to just printing the results as everything is then known at compile time.
Offline
@loqs
I do not know. I pushed this idea to point glibc in the crosshair.
The same program compiled and run under Fedora shows identical output to Archlinux.
gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9)
glibc-2.34Offline
Ubuntu (my desktop after upgrade), the optimization flags work as expected:
cribari@edgeworth:~$ apt show gcc
Package: gcc
Version: 4:9.3.0-1ubuntu2
Priority: optional
Build-Essential: yes
Section: devel
Source: gcc-defaults (1.185.1ubuntu2)
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian GCC Maintainers <debian-gcc@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 51.2 kB
Provides: c-compiler, gcc-x86-64-linux-gnu (= 4:9.3.0-1ubuntu2)
Depends: cpp (= 4:9.3.0-1ubuntu2), gcc-9 (>= 9.3.0-3~)
Recommends: libc6-dev | libc-dev
Suggests: gcc-multilib, make, manpages-dev, autoconf, automake, libtool, flex, bison, gdb, gcc-doc
Conflicts: gcc-doc (<< 1:2.95.3)
Task: ubuntustudio-video, ubuntu-mate-core, ubuntu-mate-desktop
Download-Size: 5,208 B
APT-Manual-Installed: yes
APT-Sources: http://archive.ubuntu.com/ubuntu focal/main amd64 Packages
Description: GNU C compiler
This is the GNU C compiler, a fairly portable optimizing compiler for C.
.
This is a dependency package providing the default GNU C compiler.
cribari@edgeworth:~$ apt show libc6
Package: libc6
Version: 2.31-0ubuntu9.7
Priority: required
Section: libs
Source: glibc
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: GNU Libc Maintainers <debian-glibc@lists.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 13.5 MB
Depends: libgcc-s1, libcrypt1 (>= 1:4.4.10-10ubuntu4)
Recommends: libidn2-0 (>= 2.0.5~)
Suggests: glibc-doc, debconf | debconf-2.0, locales
Conflicts: openrc (<< 0.27-2~)
Breaks: hurd (<< 1:0.9.git20170910-1), iraf-fitsutil (<< 2018.07.06-4), libtirpc1 (<< 0.2.3), locales (<< 2.31), locales-all (<< 2.31), nocache (<< 1.1-1~), nscd (<< 2.31), r-cran-later (<< 0.7.5+dfsg-2), wcc (<< 0.0.2+dfsg-3)
Replaces: libc6-amd64
Homepage: https://www.gnu.org/software/libc/libc.html
Task: minimal
Original-Vcs-Browser: https://salsa.debian.org/glibc-team/glibc
Original-Vcs-Git: https://salsa.debian.org/glibc-team/glibc.git
Download-Size: 2,714 kB
APT-Manual-Installed: yes
APT-Sources: http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
Description: GNU C Library: Shared libraries
Contains the standard libraries that are used by nearly all programs on
the system. This package includes shared versions of the standard C library
and the standard math library, as well as many others.
N: There is 1 additional record. Please use the '-a' switch to see it
cribari@edgeworth:~$ gcc -O0 coin.c && ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.13 seconds
EXECUTION TIME: 0.00 minutes
cribari@edgeworth:~$ gcc -O3 coin.c && ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
EXECUTION TIME: 0.07 seconds
EXECUTION TIME: 0.00 minutes
cribari@edgeworth:~$ EDIT: Arch with #define COIN_MAX 1000000000:
cribari@darwin7 ~ $ gcc -O0 coin.c && ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
Percentage of tails from 100000000 tosses: 50.00
Percentage of tails from 1000000000 tosses: 50.00
EXECUTION TIME: 16.43 seconds
EXECUTION TIME: 0.27 minutes
cribari@darwin7 ~ $ gcc -O3 coin.c && ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
Percentage of tails from 100000000 tosses: 50.00
Percentage of tails from 1000000000 tosses: 50.00
EXECUTION TIME: 15.87 seconds
EXECUTION TIME: 0.26 minutesUbuntu with #define COIN_MAX 1000000000:
cribari@edgeworth:~$ gcc -O0 coin.c && ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
Percentage of tails from 100000000 tosses: 50.00
Percentage of tails from 1000000000 tosses: 50.00
EXECUTION TIME: 13.05 seconds
EXECUTION TIME: 0.22 minutes
cribari@edgeworth:~$ gcc -O3 coin.c && ./a.out
Percentage of tails from 10 tosses: 60.00
Percentage of tails from 100 tosses: 54.00
Percentage of tails from 1000 tosses: 48.50
Percentage of tails from 10000 tosses: 49.55
Percentage of tails from 100000 tosses: 49.87
Percentage of tails from 1000000 tosses: 49.90
Percentage of tails from 10000000 tosses: 49.98
Percentage of tails from 100000000 tosses: 50.00
Percentage of tails from 1000000000 tosses: 50.00
EXECUTION TIME: 7.39 seconds
EXECUTION TIME: 0.12 minutesLast edited by cribari (2022-04-06 00:46:32)
Linux, street photography and Baroque music enthusiast.
Offline
the optimization flags work as expected:
Given the results in the thread so far the remaining issue is that your expectations are not matching the results due to the comparison being flawed, too many changed variables between samples and sample size is too small.
Offline