Skip to content

The performance of mimalloc is unexpectedly lower than that of the system's built-in allocator. #825

@litterbug23

Description

@litterbug23

Test Envirment: Windows 10 , MSVC 2017 x86
system malloc: 59000 (ms)
mimalloc 92000 (ms):

#include <mimalloc.h>
#include <ctime>
#include <iostream>
typedef uint32_t u32;
typedef float f32;
u32 getMicrosecondsCPU()
{
	clock_t newClock = clock();
	return (u32)((f32)(newClock) / ((f32)CLOCKS_PER_SEC / 1000000.0));
}

int main(int argc, char** argv) {
	u32 time1= getMicrosecondsCPU();
#pragma omp parallel for num_threads(6) // NEW ADD
		for (int i = 0; i < 1000000; i++)
		{
			//void* pppp = _aligned_malloc(1024, 8);
			//_aligned_free(pppp);
			void* pppp = malloc(1024);
			free(pppp);
		}
		u32 time2 = getMicrosecondsCPU();
		std::cout << "system malloc:" << (time2 - time1) << std::endl;
	}
	{
		u32 time1 = getMicrosecondsCPU();
#pragma omp parallel for num_threads(6) // NEW ADD
		for(int i = 0; i < 1000000; i++)
		{
			void* pppp = mi_malloc(1024);
			mi_free(pppp);
		}
		u32 time2 = getMicrosecondsCPU();
		std::cout <<"mimalloc: " <<  (time2 - time1) << std::endl;
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions