edefend commented on PR #6:
URL:
https://github.com/apache/trafficserver-libswoc/pull/6#issuecomment-2679933560
> @edefend thanks for working on this. Change looks good. qq though , have
you measured the performance of this?
@brbzull0 I measured the performance using a custom perf measurement tool:
```
class PerfTimer
{
public:
~PerfTimer()
{
printAll();
}
// Start or resume a timer.
void start(const std::string& name)
{
auto& timer = timers[name];
if (!timer.running)
{
timer.start_time = std::chrono::high_resolution_clock::now();
timer.running = true;
}
}
// Stop a timer and accumulate elapsed time.
void stop(const std::string& name)
{
auto& timer = timers[name];
if (timer.running)
{
auto end_time = std::chrono::high_resolution_clock::now();
timer.elapsed += std::chrono::duration<double>(end_time -
timer.start_time).count();
timer.running = false;
}
}
// Reset a timer to zero.
void reset(const std::string& name)
{
timers[name] = TimerData();
}
// Get the elapsed time for a timer.
double elapsed(const std::string& name)
{
auto& timer = timers[name];
if (timer.running)
{
auto now = std::chrono::high_resolution_clock::now();
return timer.elapsed + std::chrono::duration<double>(now -
timer.start_time).count();
}
return timer.elapsed;
}
// Print all timers.
void printAll();
private:
struct TimerData {
std::chrono::high_resolution_clock::time_point start_time;
double elapsed = 0.0;
bool running = false;
};
std::unordered_map<std::string, TimerData> timers;
};
static PerfTimer perfTimer;
```
I updated `DiscreteRange.h` with these measurements:
```
template <typename METRIC, typename PAYLOAD>
DiscreteSpace<METRIC, PAYLOAD> &
DiscreteSpace<METRIC, PAYLOAD>::mark_bulk(std::pair<range_type, PAYLOAD>*
start, size_t n)
{
// Timer [i_range]: ~1.2 seconds for n=3355591
// Loop takes ~0.357612 microseconds in total.
for (size_t i = 0; i < n; ++i)
{
auto const& [range, payload] = start[i];
this->mark(range, payload, false);
}
// Timer [tree]: ~0.06 seconds for n=3355591
// buildTree() takes ~0.017881 microseconds.
// Rebuild the entire red-black tree.
detail::RBNode* temp_head = _list.head();
_root = static_cast<Node *>(detail::RBNode::buildTree(temp_head,
_list.count()));
return *this;
}
```
If there is a way that you typically use to measure performance, let me know
and i can do that instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]