Since Old school, bare-feet and gangsters I've had some success with getting my AWS Lambda function being invoked by an upstream API Gateway managed by another part of our business. You can see how this is done in Lambda Cross Account access with Serverless framework. Recently however I've been focusing on my C++ library. I've implemented a timing function that will help me determine/measure how long my functions take to run.
I've always done this in C# by passing around delegates and anonymous function that I've book-ended by a start-time and a end-time like setup. The duration thus, is the elapsed time since the end-time less the start time. I thought I'd do a similar thing in C++ using the new C++11 lamdba expression feature like so:
#include "Timing.h"
#include <chrono>
#include <functional>
double Api::Timing::GetTimeIn(void (*functionToMeasure)(), InDuration inDuration)
{
auto start = std::chrono::high_resolution_clock::now();
functionToMeasure();
auto finish = std::chrono::high_resolution_clock::now();
double elapsed;
switch(inDuration)
{
case InDuration::Seconds:
elapsed = chrono::duration_cast<chrono::seconds>(finish - start).count();
break;
case InDuration::MilliSeconds:
elapsed = chrono::duration_cast<chrono::milliseconds>(finish - start).count();
break;
case InDuration::NanoSeconds:
elapsed = chrono::duration_cast<chrono::nanoseconds>(finish - start).count();
break;
}
return elapsed;
}
Now the interesting thing is that I've used a function pointer to pass the function to measure into the GetTimeIn() function. You can also use the std::function<void()> class that serves as a wrapper to a callable function, which would achieve the same thing. I've not actually tested this in great detail other than sleeping for about 1ms in a lambda and seeing that the result of the measurement was about 1ms.
In other news -It being Friday and all, I decided to run into the office today, I got off at Finchley road and quickly changed(The toilets were actually closed but I convinced the cleaning lady that I just wanted to change into my running kit). I headed out and then about half way my enthusiasm caught up with me and I got lost. Technically I only got lost because I could not take my planned journey in. They had removed the entrance to the canal. I Usually run along the canal so its the only way I know, So I had to improvise. I ultimately used google maps and I got back on track. A little less smooth than I otherwise hoped for but it was fine.