mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 15:29:31 +03:00
update test file
This commit is contained in:
parent
b5ae6fc555
commit
e2f4fe647e
1 changed files with 88 additions and 3 deletions
|
@ -11,7 +11,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mimalloc.h>
|
//#include <mimalloc.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -38,15 +38,17 @@ static void strdup_test(); // issue #445
|
||||||
static void heap_thread_free_huge();
|
static void heap_thread_free_huge();
|
||||||
static void test_std_string(); // issue #697
|
static void test_std_string(); // issue #697
|
||||||
static void test_thread_local(); // issue #944
|
static void test_thread_local(); // issue #944
|
||||||
|
// static void test_mixed0(); // issue #942
|
||||||
|
static void test_mixed1(); // issue #942
|
||||||
static void test_stl_allocators();
|
static void test_stl_allocators();
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// mi_stats_reset(); // ignore earlier allocations
|
// mi_stats_reset(); // ignore earlier allocations
|
||||||
|
|
||||||
|
test_mixed1();
|
||||||
//test_std_string();
|
//test_std_string();
|
||||||
test_thread_local();
|
//test_thread_local();
|
||||||
// heap_thread_free_huge();
|
// heap_thread_free_huge();
|
||||||
/*
|
/*
|
||||||
heap_thread_free_large();
|
heap_thread_free_large();
|
||||||
|
@ -179,6 +181,89 @@ static void test_stl_allocators() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
static void test_mixed0() {
|
||||||
|
std::vector<std::unique_ptr<std::size_t>> numbers(1024 * 1024 * 100);
|
||||||
|
std::vector<std::thread> threads(1);
|
||||||
|
|
||||||
|
std::atomic<std::size_t> index{};
|
||||||
|
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
|
for (auto& thread : threads) {
|
||||||
|
thread = std::thread{[&index, &numbers]() {
|
||||||
|
while (true) {
|
||||||
|
auto i = index.fetch_add(1, std::memory_order_relaxed);
|
||||||
|
if (i >= numbers.size()) return;
|
||||||
|
|
||||||
|
numbers[i] = std::make_unique<std::size_t>(i);
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& thread : threads) thread.join();
|
||||||
|
|
||||||
|
auto end = std::chrono::system_clock::now();
|
||||||
|
|
||||||
|
auto duration =
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
|
||||||
|
std::cout << "Running on " << threads.size() << " threads took " << duration
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void asd() {
|
||||||
|
void* p = malloc(128);
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
static void test_mixed1() {
|
||||||
|
std::thread thread(asd);
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// issue #691
|
||||||
|
static char* cptr;
|
||||||
|
|
||||||
|
static void* thread1_allocate()
|
||||||
|
{
|
||||||
|
cptr = mi_calloc_tp(char,22085632);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void* thread2_free()
|
||||||
|
{
|
||||||
|
assert(cptr);
|
||||||
|
mi_free(cptr);
|
||||||
|
cptr = NULL;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_large_migrate(void) {
|
||||||
|
auto t1 = std::thread(thread1_allocate);
|
||||||
|
t1.join();
|
||||||
|
auto t2 = std::thread(thread2_free);
|
||||||
|
t2.join();
|
||||||
|
/*
|
||||||
|
pthread_t thread1, thread2;
|
||||||
|
|
||||||
|
pthread_create(&thread1, NULL, &thread1_allocate, NULL);
|
||||||
|
pthread_join(thread1, NULL);
|
||||||
|
|
||||||
|
pthread_create(&thread2, NULL, &thread2_free, NULL);
|
||||||
|
pthread_join(thread2, NULL);
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// issue 445
|
// issue 445
|
||||||
static void strdup_test() {
|
static void strdup_test() {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
Loading…
Add table
Reference in a new issue