/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvxs is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #include #include #include #include #include #include #include #include "pvaproto.h" #include #include #include #include #include namespace { using namespace pvxs; struct Sampler { size_t nsamp =0; double min=0.0, max=0.0, first=0.0; double sum=0.0, sum2=0.0; void reset() { *this = {}; // zero members } void sample(double val) { if(nsamp==0u) { min = max = first = val; } else { if(max < val) max = val; else if(min > val) min = val; } sum += val; sum2 += val*val; nsamp++; } double mean() const { return sum/nsamp; } double std() const { return sqrt(sum2/nsamp - (sum/nsamp)*(sum/nsamp)); } }; std::ostream& operator<<(std::ostream& strm, const Sampler& samp) { Restore R(strm); strm<<"N="< can(niter); Sampler S; for(auto n : range(niter)) { StopWatch W; (void)W.click(); can[n] = protoype.cloneEmpty(); S.sample(W.click()); } testShow()< void benchArraySerDes(bool be, const shared_array& arr) { testDiag("%s<%s>() endian=%s", __func__, typeid (E).name(), be==hostBE ? "Host" : "Swap"); constexpr size_t niter = 1000u; shared_array scratch; evbuf ebuf(__FILE__, __LINE__, evbuffer_new()); Sampler Tser, Tdes; for(auto n : range(niter)) { (void)n; StopWatch W; { EvOutBuf buf(be, ebuf.get()); auto varr(arr.template castTo()); (void)W.click(); to_wire(buf, varr); Tser.sample(W.click()); } { EvInBuf buf(be, ebuf.get()); (void)W.click(); from_wire(buf, scratch); Tdes.sample(W.click()); } auto iarr(arr.template castTo()); auto iscratch(scratch.castTo()); if(iarr.size()!=iscratch.size() || !std::equal(iarr.begin(), iarr.end(), iscratch.begin())) testArrEq(arr.template castTo(), scratch.castTo()); } testShow()<<" Ser "< temp(nelem); for(auto n : range(temp.size())) { temp[n] = n; } shared_array arr(temp.freeze()); benchArraySerDes(hostBE, arr); benchArraySerDes(!hostBE, arr); } testDiag("baseline unoptimized for a variable size element"); { shared_array temp(nelem); for(auto n : range(temp.size())) { temp[n] = SB()<<"test"< arr(temp.freeze()); benchArraySerDes(hostBE, arr); benchArraySerDes(!hostBE, arr); } return testDone(); }