changeset 46:6fe9f5010505

Some timing calculations. I don't actually want to keep these, they're just for reference -- will back out in a mo
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 12 Sep 2016 15:17:35 +0100
parents 7668fbdcfb15
children fa2edfabf829
files json/VampJson.h
diffstat 1 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/json/VampJson.h	Fri Sep 09 11:05:44 2016 +0100
+++ b/json/VampJson.h	Mon Sep 12 15:17:35 2016 +0100
@@ -49,6 +49,8 @@
 #include "bits/PluginHandleMapper.h"
 #include "bits/RequestResponseType.h"
 
+#include <chrono>
+
 namespace vampipe {
 
 /**
@@ -317,22 +319,35 @@
 
     static std::string
     fromFloatBuffer(const float *buffer, size_t nfloats) {
+        static std::chrono::nanoseconds total;
+        auto t0 = std::chrono::high_resolution_clock::now();
         // must use char pointers, otherwise the converter will only
         // encode every 4th byte (as it will count up in float* steps)
         const char *start = reinterpret_cast<const char *>(buffer);
         const char *end = reinterpret_cast<const char *>(buffer + nfloats);
         std::string encoded;
+        encoded.reserve(16 * nfloats / 3);
         bn::encode_b64(start, end, back_inserter(encoded));
+        auto t1 = std::chrono::high_resolution_clock::now();
+        total += std::chrono::duration_cast<std::chrono::nanoseconds>(t1 - t0);
+//        std::cout << "encode: " << total.count()/1000000 << std::endl;
         return encoded;
     }
 
     static std::vector<float>
     toFloatBuffer(std::string encoded) {
+        static std::chrono::nanoseconds total;
+        auto t0 = std::chrono::high_resolution_clock::now();
         std::string decoded;
+        decoded.reserve(3 * encoded.size() / 4);
         bn::decode_b64(encoded.begin(), encoded.end(), back_inserter(decoded));
         const float *buffer = reinterpret_cast<const float *>(decoded.c_str());
         size_t n = decoded.size() / sizeof(float);
-        return std::vector<float>(buffer, buffer + n);
+        std::vector<float> result(buffer, buffer + n);
+        auto t1 = std::chrono::high_resolution_clock::now();
+        total += std::chrono::duration_cast<std::chrono::nanoseconds>(t1 - t0);
+//        std::cout << "decode: " << total.count()/1000000 << std::endl;
+        return result;
     }
 
     static json11::Json
@@ -868,6 +883,9 @@
                      const PluginHandleMapper &mapper,
                      BufferSerialisation &serialisation) {
 
+        static std::chrono::nanoseconds total;
+        auto t0 = std::chrono::high_resolution_clock::now();
+        
         std::string err;
 
         if (!j.has_shape({
@@ -909,6 +927,10 @@
             }
         }
 
+        auto t1 = std::chrono::high_resolution_clock::now();
+        total += std::chrono::duration_cast<std::chrono::nanoseconds>(t1 - t0);
+//        std::cout << "parse: " << total.count()/1000000 << std::endl;
+        
         return r;
     }