lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Is it unhelpful to move containers explicitly?


From: Greg Chicares
Subject: [lmi] Is it unhelpful to move containers explicitly?
Date: Sun, 7 Oct 2018 15:24:50 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0

As an experiment, I changed make_evaluator() to pass vector
parameters as const& instead of &&, and the measured speed did
not discernibly change. Perhaps the operation of passing these
parameters is just a negligible portion of the work done by
make_evaluator(), but even in that case wouldn't it be better
to simplify the code by not writing std::move()? See:

  
https://isocpp.org/blog/2013/02/no-really-moving-a-return-value-is-easy-stackoverflow
| often the cleanest, simplest code that doesn't even mention
| move or && anywhere is just what you want

the idea being, AIUI, that standard containers already have move
ctors and C++1X compilers will automatically use them in copy
elision if beneficial, even if we don't invoke them explicitly.

I ran 'ledger_test' ten times--without, and then with, the
patch below, thus:

/opt/lmi/src/build/lmi/Linux/gcc/ship[0]$for z in {1..10}; do wine 
./ledger_test.exe -a |grep evaluator; done

and here are totals of the ten runs, reporting two statistics:
 - mean run time for the seven runs that can be done in one second
 - lowest run time of those seven (probably more robust than mean):

    mean    least
  1.5363  1484521 explicit move (without patch)
  1.5305  1487392 with patch

Here are the data:

  explicit move (without patch):
  make_evaluator() : 1.631e-001 s mean;     149019 us least of   7 runs
  make_evaluator() : 1.555e-001 s mean;     150452 us least of   7 runs
  make_evaluator() : 1.504e-001 s mean;     147116 us least of   7 runs
  make_evaluator() : 1.507e-001 s mean;     147212 us least of   7 runs
  make_evaluator() : 1.506e-001 s mean;     147982 us least of   7 runs
  make_evaluator() : 1.551e-001 s mean;     148456 us least of   7 runs
  make_evaluator() : 1.478e-001 s mean;     146931 us least of   7 runs
  make_evaluator() : 1.513e-001 s mean;     147523 us least of   7 runs
  make_evaluator() : 1.545e-001 s mean;     146616 us least of   7 runs
  make_evaluator() : 1.573e-001 s mean;     153214 us least of   7 runs

  with patch:
  make_evaluator() : 1.480e-001 s mean;     147461 us least of   7 runs
  make_evaluator() : 1.529e-001 s mean;     146808 us least of   7 runs
  make_evaluator() : 1.523e-001 s mean;     150088 us least of   7 runs
  make_evaluator() : 1.539e-001 s mean;     147795 us least of   7 runs
  make_evaluator() : 1.540e-001 s mean;     149214 us least of   7 runs
  make_evaluator() : 1.566e-001 s mean;     149321 us least of   7 runs
  make_evaluator() : 1.480e-001 s mean;     146918 us least of   7 runs
  make_evaluator() : 1.540e-001 s mean;     147740 us least of   7 runs
  make_evaluator() : 1.564e-001 s mean;     153779 us least of   7 runs
  make_evaluator() : 1.544e-001 s mean;     148268 us least of   7 runs

and here's the patch:

---------8<--------8<--------8<--------8<--------8<--------8<--------8<-------
diff --git a/ledger_evaluator.cpp b/ledger_evaluator.cpp
index 4213e918..fdc92d9d 100644
--- a/ledger_evaluator.cpp
+++ b/ledger_evaluator.cpp
@@ -984,5 +984,6 @@ ledger_evaluator Ledger::make_evaluator() const
         }
 
-    return ledger_evaluator(std::move(stringscalars), 
std::move(stringvectors));
+//  return ledger_evaluator(std::move(stringscalars), 
std::move(stringvectors));
+    return ledger_evaluator(          stringscalars ,           stringvectors 
);
 }
 
diff --git a/ledger_evaluator.hpp b/ledger_evaluator.hpp
index 1a2230bc..3a9c6d83 100644
--- a/ledger_evaluator.hpp
+++ b/ledger_evaluator.hpp
@@ -52,5 +52,5 @@ class LMI_SO ledger_evaluator
   private:
     // Constructible only by friends: see Ledger::make_evaluator().
-    ledger_evaluator(scalar_map_t&& scalars, vector_map_t&& vectors)
+    ledger_evaluator(scalar_map_t const& scalars, vector_map_t const& vectors)
         :scalars_ {scalars}
         ,vectors_ {vectors}
--------->8-------->8-------->8-------->8-------->8-------->8-------->8-------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]