[benchmark] Review and extend Heap benchmarks (#76)

* [benchmark] Review and extend Heap benchmarks

* FoundationBenchmark only supports Apple platforms

* Rewrite CFBinaryHeap benchmarks in pure Swift
This commit is contained in:
Karoy Lorentey authored and GitHub committed 2021-08-07 14:41:02 -07:00
1 parent 940c963bc4
commit cc69069676
19 files changed
+476 -196

No files matched your search

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
#include <queue>
#include "PriorityQueueBenchmarks.h"
#include "Utils.h"
typedef std::priority_queue<intptr_t> pqueue;
void *
cpp_priority_queue_create(const intptr_t *start, size_t count)
{
auto pq = new pqueue(start, start + count);
return pq;
}
void
cpp_priority_queue_destroy(void *ptr)
{
delete static_cast<pqueue *>(ptr);
}
void
cpp_priority_queue_push(void *ptr, intptr_t value)
{
auto pq = static_cast<pqueue *>(ptr);
pq->push(value);
}
void
cpp_priority_queue_push_loop(void *ptr, const intptr_t *start, size_t count)
{
auto pq = static_cast<pqueue *>(ptr);
for (auto p = start; p < start + count; ++p) {
pq->push(*p);
}
}
intptr_t cpp_priority_queue_pop(void *ptr)
{
auto pq = static_cast<pqueue *>(ptr);
auto result = pq->top();
pq->pop();
return result;
}
void
cpp_priority_queue_pop_all(void *ptr)
{
auto pq = static_cast<pqueue *>(ptr);
while (!pq->empty()) {
black_hole(pq->top());
pq->pop();
}
}