12

I have been doing an experiment to choose between MinGW and MSVC. I decided to use Adobe C++ Performance Benchmark to do it. While MSVC's output was exceptionally faster on some operations, it was as slow on some other operations. I will add other parts of the benchmark suite when I have time to do them.

I have removed some of the benchmarks that has same results due to character limit, you can interpret them by the pattern I assume.

System Information

  • AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ 2.70GHz
  • 6GB DDR2 800MHz RAM
  • Windows 8

Any idea why the result is slow? Also, can this test's result to interpret a computer game performance (CPU physics engine maybe) because especially floating point benchmarks are slower?

-

MinGW

g++ -march=native -O3 -ffast-math -fomit-frame-pointer -momit-leaf-frame-pointer -flto -fwhole-program -ftree-loop-distribution

simple_types_loop_invariant.exe 

test                           description   absolute   operations   ratio with
number                                       time       per second   test0

 0                  "uint8_t variable add"   1.91 sec   836.38 M     1.00
 1          "uint8_t variable add hoisted"   0.08 sec   19277.11 M     0.04
 2        "uint8_t multiple variable adds"   1.93 sec   829.45 M     1.01
 3             "uint8_t variable subtract"   1.92 sec   832.47 M     1.00
 4   "uint8_t multiple variable subtracts"   2.57 sec   623.30 M     1.34
 5             "uint8_t variable multiply"   1.93 sec   831.17 M     1.01
 6  "uint8_t multiple variable multiplies"   2.56 sec   625.00 M     1.34
 7 "uint8_t multiple variable multiplies2"   1.92 sec   834.64 M     1.00
 8               "uint8_t variable divide"  10.83 sec   147.70 M     5.66
 9     "uint8_t multiple variable divides"  42.14 sec   37.97 M     22.03
10    "uint8_t multiple variable divides2"   1.93 sec   829.45 M     1.01
11       "uint8_t multiple variable mixed"   1.93 sec   828.16 M     1.01
12                  "uint8_t variable and"   1.92 sec   834.20 M     1.00
13         "uint8_t multiple variable and"   1.93 sec   828.59 M     1.01
14                   "uint8_t variable or"   1.93 sec   830.31 M     1.01
15          "uint8_t multiple variable or"   1.91 sec   836.38 M     1.00
16                  "uint8_t variable xor"   1.90 sec   840.78 M     0.99
17         "uint8_t multiple variable xor"   1.92 sec   832.47 M     1.00

Total absolute time for uint8_t loop invariant: 83.17 sec

test                           description   absolute   operations   ratio with
number                                       time       per second   test0

 0                  "int16_t variable add"   1.92 sec   835.51 M     1.00
 1          "int16_t variable add hoisted"   1.91 sec   835.95 M     1.00
 2        "int16_t multiple variable adds"   1.92 sec   833.33 M     1.00
 3             "int16_t variable subtract"   1.99 sec   804.83 M     1.04
 4   "int16_t multiple variable subtracts"   2.57 sec   622.81 M     1.34
 5             "int16_t variable multiply"   1.92 sec   832.47 M     1.00
 6  "int16_t multiple variable multiplies"   1.91 sec   838.57 M     1.00
 7 "int16_t multiple variable multiplies2"   1.92 sec   831.60 M     1.00
 8               "int16_t variable divide"  27.53 sec   58.11 M     14.38
 9     "int16_t multiple variable divides"  107.65 sec   14.86 M     56.21
10    "int16_t multiple variable divides2"   1.95 sec   819.67 M     1.02
11       "int16_t multiple variable mixed"   1.93 sec   828.16 M     1.01
12                  "int16_t variable and"   1.93 sec   828.16 M     1.01
13         "int16_t multiple variable and"   1.92 sec   831.60 M     1.00
14                   "int16_t variable or"   1.93 sec   829.88 M     1.01
15          "int16_t multiple variable or"   1.92 sec   832.90 M     1.00
16                  "int16_t variable xor"   1.93 sec   830.74 M     1.01
17         "int16_t multiple variable xor"   2.41 sec   665.00 M     1.26

Total absolute time for int16_t loop invariant: 167.16 sec

test                            description   absolute   operations   ratio with
number                                        time       per second   test0

 0                  "uint16_t variable add"   1.93 sec   830.74 M     1.00
 1          "uint16_t variable add hoisted"   0.16 sec   9937.89 M     0.08
 2        "uint16_t multiple variable adds"   1.93 sec   828.59 M     1.00
 3             "uint16_t variable subtract"   1.92 sec   835.07 M     0.99
 4   "uint16_t multiple variable subtracts"   2.56 sec   625.73 M     1.33
 5             "uint16_t variable multiply"   1.92 sec   835.07 M     0.99
 6  "uint16_t multiple variable multiplies"   2.55 sec   627.94 M     1.32
 7 "uint16_t multiple variable multiplies2"   1.92 sec   832.47 M     1.00
 8               "uint16_t variable divide"  16.08 sec   99.49 M     8.35
 9     "uint16_t multiple variable divides"  64.86 sec   24.67 M     33.68
10    "uint16_t multiple variable divides2"   1.92 sec   833.77 M     1.00
11       "uint16_t multiple variable mixed"   1.92 sec   832.03 M     1.00
12                  "uint16_t variable and"   1.92 sec   832.03 M     1.00
13         "uint16_t multiple variable and"   1.92 sec   832.03 M     1.00
14                   "uint16_t variable or"   1.93 sec   829.02 M     1.00
15          "uint16_t multiple variable or"   1.92 sec   834.20 M     1.00
16                  "uint16_t variable xor"   1.92 sec   835.07 M     0.99
17         "uint16_t multiple variable xor"   1.92 sec   834.20 M     1.00

Total absolute time for uint16_t loop invariant: 111.19 sec

test                           description   absolute   operations   ratio with
number                                       time       per second   test0

 0                  "int32_t variable add"   0.38 sec   4232.80 M     1.00
 1          "int32_t variable add hoisted"   0.33 sec   4878.05 M     0.87
 2        "int32_t multiple variable adds"   0.82 sec   1963.19 M     2.16
 3             "int32_t variable subtract"   0.64 sec   2500.00 M     1.69
 4   "int32_t multiple variable subtracts"   0.80 sec   2005.01 M     2.11
 5             "int32_t variable multiply"   2.10 sec   762.27 M     5.55
 6  "int32_t multiple variable multiplies"   8.33 sec   192.01 M     22.04
 7 "int32_t multiple variable multiplies2"   0.39 sec   4092.07 M     1.03
 8               "int32_t variable divide"  26.94 sec   59.39 M     71.27
 9     "int32_t multiple variable divides"  106.48 sec   15.03 M     281.68
10    "int32_t multiple variable divides2"   0.39 sec   4060.91 M     1.04
11       "int32_t multiple variable mixed"   0.50 sec   3187.25 M     1.33
12                  "int32_t variable and"   0.38 sec   4232.80 M     1.00
13         "int32_t multiple variable and"   0.40 sec   4030.23 M     1.05
14                   "int32_t variable or"   0.42 sec   3764.71 M     1.12
15          "int32_t multiple variable or"   0.42 sec   3855.42 M     1.10
16                  "int32_t variable xor"   0.41 sec   3950.62 M     1.07
17         "int32_t multiple variable xor"   0.38 sec   4244.03 M     1.00

Total absolute time for int32_t loop invariant: 150.49 sec

test                            description   absolute   operations   ratio with
number                                        time       per second   test0

 0                  "uint32_t variable add"   0.39 sec   4081.63 M     1.00
 1          "uint32_t variable add hoisted"   0.32 sec   4938.27 M     0.83
 2        "uint32_t multiple variable adds"   0.39 sec   4081.63 M     1.00
 3             "uint32_t variable subtract"   0.64 sec   2503.91 M     1.63
 4   "uint32_t multiple variable subtracts"   0.80 sec   2000.00 M     2.04
 5             "uint32_t variable multiply"   2.10 sec   761.54 M     5.36
 6  "uint32_t multiple variable multiplies"   2.11 sec   759.37 M     5.38
 7 "uint32_t multiple variable multiplies2"   0.39 sec   4092.07 M     1.00
 8               "uint32_t variable divide"  25.77 sec   62.08 M     65.75
 9     "uint32_t multiple variable divides"  105.98 sec   15.10 M     270.36
10    "uint32_t multiple variable divides2"   0.39 sec   4081.63 M     1.00
11       "uint32_t multiple variable mixed"   0.39 sec   4102.56 M     0.99
12                  "uint32_t variable and"   0.38 sec   4177.55 M     0.98
13         "uint32_t multiple variable and"   0.39 sec   4092.07 M     1.00
14                   "uint32_t variable or"   0.40 sec   4020.10 M     1.02
15          "uint32_t multiple variable or"   0.40 sec   4010.03 M     1.02
16                  "uint32_t variable xor"   0.39 sec   4071.25 M     1.00
17         "uint32_t multiple variable xor"   0.38 sec   4188.48 M     0.97

Total absolute time for uint32_t loop invariant: 142.03 sec

test                           description   absolute   operations   ratio with
number                                       time       per second   test0

 0                  "int64_t variable add"   0.80 sec   1997.50 M     1.00
 1          "int64_t variable add hoisted"   0.66 sec   2442.75 M     0.82
 2        "int64_t multiple variable adds"   1.66 sec   962.70 M     2.07
 3             "int64_t variable subtract"   1.30 sec   1233.62 M     1.62
 4   "int64_t multiple variable subtracts"   1.61 sec   991.33 M     2.01
 5             "int64_t variable multiply"   5.83 sec   274.40 M     7.28
 6  "int64_t multiple variable multiplies"  24.06 sec   66.50 M     30.04
 7 "int64_t multiple variable multiplies2"   0.85 sec   1880.14 M     1.06
 8               "int64_t variable divide"  43.13 sec   37.10 M     53.84
 9     "int64_t multiple variable divides"  166.87 sec    9.59 M     208.32
10    "int64_t multiple variable divides2"   0.79 sec   2025.32 M     0.99
11       "int64_t multiple variable mixed"   0.99 sec   1617.80 M     1.23
12                  "int64_t variable and"   0.79 sec   2033.04 M     0.98
13         "int64_t multiple variable and"   0.77 sec   2075.23 M     0.96
14                   "int64_t variable or"   0.79 sec   2030.46 M     0.98
15          "int64_t multiple variable or"   0.78 sec   2059.20 M     0.97
16                  "int64_t variable xor"   0.78 sec   2051.28 M     0.97
17         "int64_t multiple variable xor"   0.79 sec   2035.62 M     0.98

Total absolute time for int64_t loop invariant: 253.23 sec

test                            description   absolute   operations   ratio with
number                                        time       per second   test0

 0                  "uint64_t variable add"   0.78 sec   2064.52 M     1.00
 1          "uint64_t variable add hoisted"   0.66 sec   2435.31 M     0.85
 2        "uint64_t multiple variable adds"   0.79 sec   2025.32 M     1.02
 3             "uint64_t variable subtract"   1.29 sec   1241.27 M     1.66
 4   "uint64_t multiple variable subtracts"   1.60 sec   1001.88 M     2.06
 5             "uint64_t variable multiply"   5.98 sec   267.56 M     7.72
 6  "uint64_t multiple variable multiplies"   5.81 sec   275.48 M     7.49
 7 "uint64_t multiple variable multiplies2"   0.79 sec   2027.88 M     1.02
 8               "uint64_t variable divide"  38.20 sec   41.89 M     49.28
 9     "uint64_t multiple variable divides"  151.00 sec   10.60 M     194.83
10    "uint64_t multiple variable divides2"   0.79 sec   2020.20 M     1.02
11       "uint64_t multiple variable mixed"   0.78 sec   2064.52 M     1.00
12                  "uint64_t variable and"   0.78 sec   2056.56 M     1.00
13         "uint64_t multiple variable and"   0.79 sec   2030.46 M     1.02
14                   "uint64_t variable or"   0.77 sec   2080.62 M     0.99
15          "uint64_t multiple variable or"   0.79 sec   2020.20 M     1.02
16                  "uint64_t variable xor"   0.78 sec   2040.82 M     1.01
17         "uint64_t multiple variable xor"   0.77 sec   2069.86 M     1.00

Total absolute time for uint64_t loop invariant: 213.13 sec

test                         description   absolute   operations   ratio with
number                                     time       per second   test0

 0                  "float variable add"   0.41 sec   3874.09 M     1.00
 1          "float variable add hoisted"   0.33 sec   4923.08 M     0.79
 2        "float multiple variable adds"   0.41 sec   3892.94 M     1.00
 3             "float variable subtract"   0.39 sec   4081.63 M     0.95
 4   "float multiple variable subtracts"   1.37 sec   1170.45 M     3.31
 5             "float variable multiply"   0.33 sec   4892.97 M     0.79
 6  "float multiple variable multiplies"   0.32 sec   5079.37 M     0.76
 7 "float multiple variable multiplies2"   0.41 sec   3940.89 M     0.98
 8               "float variable divide"   0.33 sec   4907.98 M     0.79
 9     "float multiple variable divides"   0.33 sec   4833.84 M     0.80
10    "float multiple variable divides2"   0.40 sec   3970.22 M     0.98
11       "float multiple variable mixed"   0.40 sec   4050.63 M     0.96

Total absolute time for float loop invariant: 5.41 sec

test                          description   absolute   operations   ratio with
number                                      time       per second   test0

 0                  "double variable add"   0.80 sec   1990.05 M     1.00
 1          "double variable add hoisted"   0.65 sec   2457.76 M     0.81
 2        "double multiple variable adds"   0.79 sec   2017.65 M     0.99
 3             "double variable subtract"   0.82 sec   1960.78 M     1.01
 4   "double multiple variable subtracts"   2.72 sec   587.37 M     3.39
 5             "double variable multiply"   0.76 sec   2110.82 M     0.94
 6  "double multiple variable multiplies"   0.78 sec   2048.66 M     0.97
 7 "double multiple variable multiplies2"   0.80 sec   1995.01 M     1.00
 8               "double variable divide"   0.67 sec   2388.06 M     0.83
 9     "double multiple variable divides"   0.66 sec   2420.57 M     0.82
10    "double multiple variable divides2"   0.80 sec   2007.53 M     0.99
11       "double multiple variable mixed"   0.81 sec   1968.02 M     1.01

Total absolute time for double loop invariant: 11.07 sec

-

Visual C++ 11.0

cl /O2 /Ob2 /Oi /Oy /GL /MD /GS- /Gy /Qpar /arch:SSE2 /fp:fast /GR- simple_types_loop_invariant.cpp

simple_types_loop_invariant.exe 

test                           description   absolute   operations   ratio with
number                                       time       per second   test0

 0                  "uint8_t variable add"   0.17 sec   9638.55 M     1.00
 1          "uint8_t variable add hoisted"   0.11 sec   15094.34 M     0.64
 2        "uint8_t multiple variable adds"   0.89 sec   1801.80 M     5.35
 3             "uint8_t variable subtract"   0.17 sec   9638.55 M     1.00
 4   "uint8_t multiple variable subtracts"   3.51 sec   456.23 M     21.13
 5             "uint8_t variable multiply"   2.23 sec   719.10 M     13.40
 6  "uint8_t multiple variable multiplies"   4.48 sec   356.98 M     27.00
 7 "uint8_t multiple variable multiplies2"   1.29 sec   1239.35 M     7.78
 8               "uint8_t variable divide"  27.23 sec   58.76 M     164.03
 9     "uint8_t multiple variable divides"  108.58 sec   14.74 M     654.11
10    "uint8_t multiple variable divides2"   1.28 sec   1252.94 M     7.69
11       "uint8_t multiple variable mixed"   1.27 sec   1264.82 M     7.62
12                  "uint8_t variable and"   1.28 sec   1247.08 M     7.73
13         "uint8_t multiple variable and"   3.52 sec   454.16 M     21.22
14                   "uint8_t variable or"   1.28 sec   1254.90 M     7.68
15          "uint8_t multiple variable or"   3.54 sec   452.36 M     21.31
16                  "uint8_t variable xor"   1.27 sec   1256.87 M     7.67
17         "uint8_t multiple variable xor"   3.49 sec   457.93 M     21.05

Total absolute time for uint8_t loop invariant: 165.57 sec

test                           description   absolute   operations   ratio with
number                                       time       per second   test0

 0                  "int16_t variable add"   0.33 sec   4923.08 M     1.00
 1          "int16_t variable add hoisted"   0.21 sec   7804.88 M     0.63
 2        "int16_t multiple variable adds"   0.76 sec   2094.24 M     2.35
 3             "int16_t variable subtract"   0.32 sec   5063.29 M     0.97
 4   "int16_t multiple variable subtracts"   2.02 sec   790.12 M     6.23
 5             "int16_t variable multiply"   1.61 sec   995.64 M     4.94
 6  "int16_t multiple variable multiplies"   4.45 sec   359.31 M     13.70
 7 "int16_t multiple variable multiplies2"   1.13 sec   1418.44 M     3.47
 8               "int16_t variable divide"  27.24 sec   58.74 M     83.81
 9     "int16_t multiple variable divides"  109.33 sec   14.64 M     336.39
10    "int16_t multiple variable divides2"   0.97 sec   1654.60 M     2.98
11       "int16_t multiple variable mixed"   0.61 sec   2631.58 M     1.87
12                  "int16_t variable and"   1.12 sec   1433.69 M     3.43
13         "int16_t multiple variable and"   1.77 sec   904.47 M     5.44
14                   "int16_t variable or"   1.20 sec   1330.01 M     3.70
15          "int16_t multiple variable or"   1.77 sec   906.00 M     5.43
16                  "int16_t variable xor"   1.12 sec   1432.41 M     3.44
17         "int16_t multiple variable xor"   1.77 sec   905.49 M     5.44

Total absolute time for int16_t loop invariant: 157.70 sec

test                            description   absolute   operations   ratio with
number                                        time       per second   test0

 0                  "uint16_t variable add"   0.33 sec   4833.84 M     1.00
 1          "uint16_t variable add hoisted"   0.21 sec   7729.47 M     0.63
 2        "uint16_t multiple variable adds"   0.78 sec   2059.20 M     2.35
 3             "uint16_t variable subtract"   0.32 sec   5031.45 M     0.96
 4   "uint16_t multiple variable subtracts"   2.03 sec   786.63 M     6.15
 5             "uint16_t variable multiply"   1.61 sec   993.79 M     4.86
 6  "uint16_t multiple variable multiplies"   4.45 sec   359.71 M     13.44
 7 "uint16_t multiple variable multiplies2"   1.12 sec   1428.57 M     3.38
 8               "uint16_t variable divide"  27.15 sec   58.94 M     82.01
 9     "uint16_t multiple variable divides"  109.41 sec   14.62 M     330.53
10    "uint16_t multiple variable divides2"   2.42 sec   661.70 M     7.31
11       "uint16_t multiple variable mixed"   2.43 sec   658.71 M     7.34
12                  "uint16_t variable and"   2.53 sec   632.91 M     7.64
13         "uint16_t multiple variable and"   3.21 sec   498.75 M     9.69
14                   "uint16_t variable or"   2.52 sec   633.91 M     7.63
15          "uint16_t multiple variable or"   3.19 sec   501.25 M     9.64
16                  "uint16_t variable xor"   2.52 sec   634.92 M     7.61
17         "uint16_t multiple variable xor"   3.21 sec   498.29 M     9.70

Total absolute time for uint16_t loop invariant: 169.43 sec

test                           description   absolute   operations   ratio with
number                                       time       per second   test0

 0                  "int32_t variable add"   0.64 sec   2519.69 M     1.00
 1          "int32_t variable add hoisted"   0.41 sec   3902.44 M     0.65
 2        "int32_t multiple variable adds"   0.97 sec   1654.60 M     1.52
 3             "int32_t variable subtract"   0.63 sec   2539.68 M     0.99
 4   "int32_t multiple variable subtracts"   0.97 sec   1651.19 M     1.53
 5             "int32_t variable multiply"   2.01 sec   797.61 M     3.16
 6  "int32_t multiple variable multiplies"   4.17 sec   383.60 M     6.57
 7 "int32_t multiple variable multiplies2"   1.27 sec   1262.83 M     2.00
 8               "int32_t variable divide"  26.87 sec   59.55 M     42.31
 9     "int32_t multiple variable divides"  108.12 sec   14.80 M     170.27
10    "int32_t multiple variable divides2"   0.96 sec   1673.64 M     1.51
11       "int32_t multiple variable mixed"   0.52 sec   3082.85 M     0.82
12                  "int32_t variable and"   0.66 sec   2431.61 M     1.04
13         "int32_t multiple variable and"   0.98 sec   1626.02 M     1.55
14                   "int32_t variable or"   0.65 sec   2472.95 M     1.02
15          "int32_t multiple variable or"   0.96 sec   1673.64 M     1.51
16                  "int32_t variable xor"   0.65 sec   2480.62 M     1.02
17         "int32_t multiple variable xor"   0.95 sec   1682.44 M     1.50

Total absolute time for int32_t loop invariant: 152.36 sec

test                            description   absolute   operations   ratio with
number                                        time       per second   test0

 0                  "uint32_t variable add"   0.65 sec   2446.48 M     1.00
 1          "uint32_t variable add hoisted"   0.41 sec   3911.98 M     0.63
 2        "uint32_t multiple variable adds"   0.96 sec   1671.89 M     1.46
 3             "uint32_t variable subtract"   0.66 sec   2435.31 M     1.00
 4   "uint32_t multiple variable subtracts"   0.97 sec   1647.79 M     1.48
 5             "uint32_t variable multiply"   1.92 sec   834.64 M     2.93
 6  "uint32_t multiple variable multiplies"   4.45 sec   359.71 M     6.80
 7 "uint32_t multiple variable multiplies2"   1.30 sec   1230.77 M     1.99
 8               "uint32_t variable divide"  26.33 sec   60.77 M     40.26
 9     "uint32_t multiple variable divides"  99.86 sec   16.02 M     152.69
10    "uint32_t multiple variable divides2"   0.95 sec   1691.33 M     1.45
11       "uint32_t multiple variable mixed"   0.54 sec   2962.96 M     0.83
12                  "uint32_t variable and"   0.65 sec   2476.78 M     0.99
13         "uint32_t multiple variable and"   0.96 sec   1661.47 M     1.47
14                   "uint32_t variable or"   0.65 sec   2469.14 M     0.99
15          "uint32_t multiple variable or"   0.95 sec   1678.91 M     1.46
16                  "uint32_t variable xor"   0.65 sec   2461.54 M     0.99
17         "uint32_t multiple variable xor"   0.97 sec   1654.60 M     1.48

Total absolute time for uint32_t loop invariant: 143.81 sec

test                           description   absolute   operations   ratio with
number                                       time       per second   test0

 0                  "int64_t variable add"   1.30 sec   1233.62 M     1.00
 1          "int64_t variable add hoisted"   0.81 sec   1987.58 M     0.62
 2        "int64_t multiple variable adds"   1.96 sec   817.58 M     1.51
 3             "int64_t variable subtract"   1.30 sec   1226.99 M     1.01
 4   "int64_t multiple variable subtracts"   1.94 sec   825.17 M     1.49
 5             "int64_t variable multiply"   7.17 sec   223.06 M     5.53
 6  "int64_t multiple variable multiplies"  24.97 sec   64.08 M     19.25
 7 "int64_t multiple variable multiplies2"   1.97 sec   810.54 M     1.52
 8               "int64_t variable divide"  62.56 sec   25.58 M     48.24
 9     "int64_t multiple variable divides"  246.80 sec    6.48 M     190.29
10    "int64_t multiple variable divides2"   1.94 sec   824.74 M     1.50
11       "int64_t multiple variable mixed"   0.80 sec   2002.50 M     0.62
12                  "int64_t variable and"   1.28 sec   1249.02 M     0.99
13         "int64_t multiple variable and"   1.94 sec   823.89 M     1.50
14                   "int64_t variable or"   1.29 sec   1236.48 M     1.00
15          "int64_t multiple variable or"   1.94 sec   826.45 M     1.49
16                  "int64_t variable xor"   1.29 sec   1237.43 M     1.00
17         "int64_t multiple variable xor"   1.95 sec   822.62 M     1.50

Total absolute time for int64_t loop invariant: 363.21 sec

test                            description   absolute   operations   ratio with
number                                        time       per second   test0

 0                  "uint64_t variable add"   1.29 sec   1237.43 M     1.00
 1          "uint64_t variable add hoisted"   0.82 sec   1941.75 M     0.64
 2        "uint64_t multiple variable adds"   1.95 sec   820.93 M     1.51
 3             "uint64_t variable subtract"   1.30 sec   1226.05 M     1.01
 4   "uint64_t multiple variable subtracts"   2.06 sec   777.45 M     1.59
 5             "uint64_t variable multiply"   7.42 sec   215.78 M     5.73
 6  "uint64_t multiple variable multiplies"  26.28 sec   60.88 M     20.33
 7 "uint64_t multiple variable multiplies2"   1.97 sec   810.54 M     1.53
 8               "uint64_t variable divide"  61.84 sec   25.87 M     47.83
 9     "uint64_t multiple variable divides"  235.73 sec    6.79 M     182.31
10    "uint64_t multiple variable divides2"   1.98 sec   806.45 M     1.53
11       "uint64_t multiple variable mixed"   1.05 sec   1519.47 M     0.81
12                  "uint64_t variable and"   1.29 sec   1244.17 M     0.99
13         "uint64_t multiple variable and"   1.95 sec   821.78 M     1.51
14                   "uint64_t variable or"   1.29 sec   1236.48 M     1.00
15          "uint64_t multiple variable or"   1.94 sec   823.05 M     1.50
16                  "uint64_t variable xor"   1.29 sec   1242.24 M     1.00
17         "uint64_t multiple variable xor"   1.95 sec   819.67 M     1.51

Total absolute time for uint64_t loop invariant: 353.42 sec

test                         description   absolute   operations   ratio with
number                                     time       per second   test0

 0                  "float variable add"   0.65 sec   2450.23 M     1.00
 1          "float variable add hoisted"   0.41 sec   3892.94 M     0.63
 2        "float multiple variable adds"   1.60 sec   998.75 M     2.45
 3             "float variable subtract"   0.65 sec   2472.95 M     0.99
 4   "float multiple variable subtracts"   1.61 sec   996.88 M     2.46
 5             "float variable multiply"   0.63 sec   2531.65 M     0.97
 6  "float multiple variable multiplies"   1.30 sec   1231.72 M     1.99
 7 "float multiple variable multiplies2"   0.64 sec   2503.91 M     0.98
 8               "float variable divide"   0.65 sec   2457.76 M     1.00
 9     "float multiple variable divides"   1.29 sec   1240.31 M     1.98
10    "float multiple variable divides2"   0.65 sec   2476.78 M     0.99
11       "float multiple variable mixed"   0.97 sec   1646.09 M     1.49

Total absolute time for float loop invariant: 11.05 sec

test                          description   absolute   operations   ratio with
number                                      time       per second   test0

 0                  "double variable add"   1.33 sec   1203.91 M     1.00
 1          "double variable add hoisted"   0.84 sec   1911.59 M     0.63
 2        "double multiple variable adds"   3.20 sec   499.69 M     2.41
 3             "double variable subtract"   1.29 sec   1238.39 M     0.97
 4   "double multiple variable subtracts"   3.24 sec   493.83 M     2.44
 5             "double variable multiply"   1.29 sec   1237.43 M     0.97
 6  "double multiple variable multiplies"   2.59 sec   618.00 M     1.95
 7 "double multiple variable multiplies2"   1.28 sec   1247.08 M     0.97
 8               "double variable divide"   5.12 sec   312.44 M     3.85
 9     "double multiple variable divides"  31.99 sec   50.01 M     24.07
10    "double multiple variable divides2"   1.29 sec   1240.31 M     0.97
11       "double multiple variable mixed"   1.94 sec   824.74 M     1.46

Total absolute time for double loop invariant: 55.41 sec
4

2 回答 2

7

我想补充一下 Mats 所说的内容(我第二个),你可以只编写你需要的特定应用程序,并在具有不同优化标志的成品上尝试两者(例如,你可以使用 -Ofast 标志从 gcc 或其他允许惰性除法的标志等),看看是否有任何显着差异。

但在此之前,您只需回答以下问题:

  • 我的程序够快吗?大多数程序都不受 CPU 限制,或者如果它们是,您不需要现在更快。
  • 我的程序大部分时间都浪费在哪里了?
  • 有没有更高效的算法?
  • 内存消耗如何?
  • IO怎么样?

要回答这些问题,您所需要的只是分析和算法基础(如果需要,还可以进行一些组装,但没有它您可以做很多事情)。除非两个编译器给出非常不同的结果(这不应该发生),否则您实际上并不关心哪个编译器可以让您在程序中节省 10 秒(10 分钟内)。

大多数时候,程序慢不是因为编译器,而是因为程序员。为了说明我的观点,您可以查看以下内容:http: //blog.golang.org/2011/06/profiling-go-programs.html 不,我不打算将您转换为任何其他编程语言!但是发布它的人给我留下了深刻的印象,我想你会的。

于 2013-02-06T16:58:36.900 回答
6

Different compilers generate different code for different (types of) operations. Without compiling the code with both compilers and comparing the assembler code generated, it's pretty hard to answer why one is better/worse than the other.

It is also probably not a great idea to take what appears to be fairly trivial functions (I'm too lazy to actually download and look at the code - I'm just reading the benchmark names and with experience of similar benchmarks drawing this conclusion), and from that draw the conclusion that you get the same level of improvement on a much larger piece of code. If you have a loop that can be solved by using one instruction or two instructions, and one compiler decides to use the "two instructions" (for whatever arbitrary reason compilers decide these things), then the whole loop may be 30-50% slower with two instructions. But that doesn't mean that if you do something else in the loop, that adds another four instructions in both compilers, the loop is still that much faster, right?

Even minute differences in instruction ordering or alignment can sometimes make a big difference on benchmarks with very small loops.

于 2013-02-06T16:42:49.000 回答