mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-01-22 20:38:01 -05:00
1. Another set of arguments optimized: * args-by-val converted to args-by-ref * in some cases, reverse has been done, if that is better: if the object's copy is modified in the func, it's better to avoid extra copy from arg to local var 2. some const functions marked as such (this is just a beginning) 3. iterators were replaced with const_iterators where applicable 4. catches that catch std::exception& changed to catch (...) - that is safer; if exception handling is restructured, this will have to be reconsidered anyway 5. removed some basic structures' constructors; changed them to hold const char*s to avoid unnecessary string constructions; 6. in some places, moved variable declarations to their definitions, to avoid calling default constructors and then assigning 7. removed some unnecessary shared_pointers in favor of local objects; 8. in FORTRAN-style functions, added const specifiers to input doubles; 9. fixed a place where values were inserted into a map while iterating through it 10. fixed is_valid_*_derivative: they could accept incorrect values and throw when upper index is less than lower
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
#include <memory>
|
|
#include "SpeedTest.h"
|
|
#include "AbstractState.h"
|
|
#include "DataStructures.h"
|
|
#include "crossplatform_shared_ptr.h"
|
|
|
|
#include <time.h>
|
|
|
|
// A hack to make powerpc happy since sysClkRateGet not found
|
|
#if defined(__powerpc__)
|
|
#define CLOCKS_PER_SEC 1000
|
|
#endif
|
|
|
|
namespace CoolProp{
|
|
|
|
void compare_REFPROP_and_CoolProp(const std::string &fluid, CoolProp::input_pairs inputs, double val1, double val2, std::size_t N, double d1, double d2)
|
|
{
|
|
time_t t1,t2;
|
|
|
|
shared_ptr<AbstractState> State(AbstractState::factory("HEOS", fluid));
|
|
t1 = clock();
|
|
for (std::size_t ii = 0; ii < N; ++ii)
|
|
{
|
|
State->update(inputs, val1 + ii*d1, val2 + ii*d2);
|
|
}
|
|
t2 = clock();
|
|
|
|
double elap = ((double)(t2-t1))/CLOCKS_PER_SEC/((double)N)*1e6;
|
|
printf("Elapsed time for CoolProp is %g us/call\n",elap);
|
|
|
|
State.reset(AbstractState::factory("REFPROP", fluid));
|
|
t1 = clock();
|
|
for (std::size_t ii = 0; ii < N; ++ii)
|
|
{
|
|
State->update(inputs, val1 + ii*d1, val2 + ii*d2);
|
|
}
|
|
t2 = clock();
|
|
elap = ((double)(t2-t1))/CLOCKS_PER_SEC/((double)N)*1e6;
|
|
printf("Elapsed time for REFPROP is %g us/call\n",elap);
|
|
}
|
|
|
|
} /* namespace CoolProp */
|