[Dune] Dune on Windows MinGW

Jö Fahlke jorrit at jorrit.de
Wed May 4 17:57:12 CEST 2011


Am Wed,  4. May 2011, 15:28:57 +0200 schrieb Carsten Gräser:
> You can check the optimization yourself with the attached example.

Thanks Carsten :)

I adapted your example to output timings for each operation.  I also added a
fourth example and made the mathematical operation exchangable.  The new
programm is attached, the results are below.

The essence is that Carsten is right, with one exception.  For g++-4.1 only
exp(1.0) seems to be optimized in this way.  So it boils down to how serious
we take our commitment to support g++-4.1.

Bye,
Jö.

Example 1:
  static const double e = EXPR(ARG);
  for (int i=0; i<n; ++i)
      y += e;

Example 2:
  template<>
  struct MathematicalConstants< double >
  {
    static double e () { return EXPR(ARG); }
  };
  for (int i=0; i<n; ++i)
      y += MathematicalConstants<double>::e();

Example 3:
  x = ARG;
  for (int i=0; i<n; ++i)
      y += EXPR(x);

Example 4:
  const double &local_const() {
    static const double e = EXPR(ARG);
    return e;
  }
  for (int i=0; i<n; ++i)
    y += local_const();

I used n=500000000 and -O3.  Times are in seconds.  g++-4.5 is a Debian
prerelease snapshot.

#define EXPR(x) std::exp(x)
#define ARG 1.0
|         | Example 1 | Example 2 | Example 3 | Example 4 |
|---------+-----------+-----------+-----------+-----------|
| g++-4.1 |      1.81 |      1.80 |     34.32 |      1.81 |
| g++-4.3 |      0.60 |      0.61 |     34.19 |      0.61 |
| g++-4.4 |      0.60 |      0.60 |     34.39 |      0.60 |
| g++-4.5 |      0.59 |      0.60 |     34.57 |      0.60 |
| clang++ |      1.80 |      1.80 |     35.03 |      1.81 |

#define EXPR(x) std::acos(x)
#define ARG -1.0
|         | Example 1 | Example 2 | Example 3 | Example 4 |
|---------+-----------+-----------+-----------+-----------|
| g++-4.1 |      1.81 |     24.38 |     21.42 |      1.81 |
| g++-4.3 |      0.60 |      0.60 |     21.42 |      0.60 |
| g++-4.4 |      0.62 |      0.60 |     21.98 |      0.60 |
| g++-4.5 |      0.60 |      0.61 |     22.55 |      0.60 |
| clang++ |      1.80 |      1.81 |     21.95 |      1.81 |

#define EXPR(x) std::log(x)
#define ARG 2.0
|         | Example 1 | Example 2 | Example 3 | Example 4 |
|---------+-----------+-----------+-----------+-----------|
| g++-4.1 |      1.80 |     24.80 |     20.92 |      1.81 |
| g++-4.3 |      0.60 |      0.60 |     20.95 |      0.60 |
| g++-4.4 |      0.60 |      0.60 |     20.54 |      0.60 |
| g++-4.5 |      0.60 |      0.61 |     20.71 |      0.60 |
| clang++ |      1.81 |      1.81 |     20.85 |      1.80 |

-- 
Kiss a non-smoker; taste the difference.
-- fortune
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compile_time_expressions.cc
Type: text/x-c++src
Size: 1975 bytes
Desc: not available
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20110504/5f462601/attachment.cc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: Digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20110504/5f462601/attachment.sig>


More information about the Dune mailing list