// File: walker-xian[P]teisye/heapperf/heapperf.cpp
// Function: application::test(statistic (&) [5], int)
void test(case_statistics_t& cs, int core) noexcept
    {
		// bind current thread to one core, thus, don't have to sync TSC among cores.
		int errcode{};
#if defined(_WIN32)
		if (!SetThreadAffinityMask(GetCurrentThread(), 1ULL << core))
		{
			errcode = GetLastError();
		}
#else
		cpu_set_t cpuset;
		CPU_ZERO(&cpuset);
		CPU_SET(core, &cpuset); 
		errcode = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
#endif
		if (errcode)
		{
			cerr << "Failed to bind current thread to core #" << core << ", errcode=" << errcode << endl;
			return;
		}
		// ensure current thread will run on desired core.
		this_thread::sleep_for(10ms);

        switch (_allocator_id)
        {
        case _malloc:
            _active_allocator = ::malloc;
            _active_deallocator = ::free;
            break;
        case _teisye:
            _active_allocator = ::tsalloc;
            _active_deallocator = ::tsfree;
            break;
        default:
            assert(0);
            break;
        }

        for (int n = 0; n < 10; ++n)
        {    	
            if (1 & _case_mask)
            {
                _active_statistic = &cs[_wc];
                test_wc();
            }

            for (int i = 1; i < _test_case_count; ++i)
            {
                if (!((1 << i) & _case_mask)) continue;

                unique_ptr<uint8_t> allocations[8];
                int pos{};

                _active_statistic = &cs[i];
                auto &tc = _test_cases[i];
                for (size_t size = _test_cases[i - 1]._max_size; size < tc._max_size; size += tc._step)
                {
                    auto p = new uint8_t[size];
                    memset(p, 0xbd, size);
                    allocations[pos] = unique_ptr<uint8_t>(p);

                    // hold a little while
                    pos = (pos + 1) % (sizeof(allocations)/sizeof(allocations[0]));
                    if (pos == 0)
                    {
                        for (auto &item : allocations) 
                            item.reset();
                    }
                }
            }
        }

        _active_statistic = &_default_statistic;
        _active_allocator = ::tsalloc;
        _active_deallocator = ::tsfree;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
movl $0x0, -0x18(%rbp)
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x5210
jmp 0x77ad
movslq -0x14(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
shrq $0x3, %rax
cmpq $0x80, %rax
jae 0x7802
movq -0xa0(%rbp), %rcx
andq $0x3f, %rcx
movl $0x1, %eax
shlq %cl, %rax
movq -0xa0(%rbp), %rcx
shrq $0x6, %rcx
orq -0x98(%rbp,%rcx,8), %rax
movq %rax, -0x98(%rbp,%rcx,8)
movq %rax, -0x158(%rbp)
jmp 0x780d
xorl %eax, %eax
movq %rax, -0x158(%rbp)
jmp 0x780d
movq -0x158(%rbp), %rax
movq %rax, -0xa8(%rbp)
callq 0x53b0
movq %rax, %rdi
movl $0x80, %esi
leaq -0x98(%rbp), %rdx
callq 0x5660
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x78c3
movq 0x4f7a0(%rip), %rdi     # 0x56fe8
leaq 0x32acf(%rip), %rsi     # 0x3a31e
callq 0x53e0
movq %rax, -0x160(%rbp)
jmp 0x785d
movq -0x160(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x5640
movq %rax, -0x168(%rbp)
jmp 0x7875
movq -0x168(%rbp), %rdi
leaq 0x32ac3(%rip), %rsi     # 0x3a346
callq 0x53e0
movq %rax, -0x170(%rbp)
jmp 0x7891
movq -0x170(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x5640
movq %rax, -0x178(%rbp)
jmp 0x78a9
movq -0x178(%rbp), %rdi
movq 0x4f6a9(%rip), %rsi     # 0x56f60
callq 0x5420
jmp 0x78be
jmp 0x7ccf
callq 0x9180
movq %rax, -0x180(%rbp)
jmp 0x78d1
movq -0x180(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x90d0
jmp 0x78ed
movq -0x150(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, -0x184(%rbp)
testl %eax, %eax
je 0x7910
jmp 0x7903
movl -0x184(%rbp), %eax
subl $0x1, %eax
je 0x7946
jmp 0x797c
movq %fs:0x0, %rax
leaq -0x1b8(%rax), %rax
movq 0x4f681(%rip), %rcx     # 0x56fa8
movq %rcx, (%rax)
movq %fs:0x0, %rax
leaq -0x1b0(%rax), %rax
movq 0x4f64f(%rip), %rcx     # 0x56f90
movq %rcx, (%rax)
jmp 0x799b
movq %fs:0x0, %rax
leaq -0x1b8(%rax), %rax
leaq 0x2f223(%rip), %rcx     # 0x36b80
movq %rcx, (%rax)
movq %fs:0x0, %rax
leaq -0x1b0(%rax), %rax
leaq 0x2f239(%rip), %rcx     # 0x36bb0
movq %rcx, (%rax)
jmp 0x799b
leaq 0x329ce(%rip), %rdi     # 0x3a351
leaq 0x329c9(%rip), %rsi     # 0x3a353
movl $0x109, %edx            # imm = 0x109
leaq 0x329d3(%rip), %rcx     # 0x3a369
callq 0x52e0
movl $0x0, -0xb4(%rbp)
cmpl $0xa, -0xb4(%rbp)
jge 0x7c81
movq -0x150(%rbp), %rax
movl 0x84(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x79e4
movq -0x150(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, %fs:-0x1a8
callq 0x91a0
jmp 0x79e2
jmp 0x79e4
movl $0x1, -0xb8(%rbp)
cmpl $0x5, -0xb8(%rbp)
jge 0x7c6b
movl -0xb8(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movq -0x150(%rbp), %rcx
andl 0x84(%rcx), %eax
cmpl $0x0, %eax
jne 0x7a1f
jmp 0x7c57
leaq -0x100(%rbp), %rax
movq %rax, %rcx
addq $0x40, %rcx
movq %rcx, -0x198(%rbp)
movq %rax, -0x190(%rbp)
movq -0x190(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x9400
movq -0x1a0(%rbp), %rax
movq -0x198(%rbp), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x190(%rbp)
jne 0x7a3b
movq -0x150(%rbp), %rax
movl $0x0, -0x104(%rbp)
movq -0x10(%rbp), %rdx
movslq -0xb8(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rdx
movq %fs:0x0, %rcx
leaq -0x1a8(%rcx), %rcx
movq %rdx, (%rcx)
movslq -0xb8(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x110(%rbp)
movl -0xb8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq -0x110(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x7c0b
movq -0x118(%rbp), %rdi
callq 0x58f0
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rdx
movl $0xbd, %esi
callq 0x5210
movq -0x120(%rbp), %rsi
leaq -0x128(%rbp), %rdi
callq 0x9430
movslq -0x104(%rbp), %rax
leaq -0x100(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x128(%rbp), %rsi
callq 0x9460
leaq -0x128(%rbp), %rdi
callq 0x9490
movl -0x104(%rbp), %eax
addl $0x1, %eax
cltq
andq $0x7, %rax
movl %eax, -0x104(%rbp)
cmpl $0x0, -0x104(%rbp)
jne 0x7beb
leaq -0x100(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x130(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x140(%rbp)
movq -0x138(%rbp), %rax
cmpq -0x140(%rbp), %rax
je 0x7be9
movq -0x138(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x94e0
movq -0x138(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x138(%rbp)
jmp 0x7ba7
jmp 0x7beb
jmp 0x7bed
movq -0x110(%rbp), %rax
movq 0x10(%rax), %rax
addq -0x118(%rbp), %rax
movq %rax, -0x118(%rbp)
jmp 0x7ad8
leaq -0x100(%rbp), %rax
movq %rax, -0x1b0(%rbp)
addq $0x40, %rax
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rdi
addq $-0x8, %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x9490
movq -0x1b0(%rbp), %rcx
movq -0x1b8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1a8(%rbp)
jne 0x7c24
jmp 0x7c57
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x79ee
jmp 0x7c6d
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x79a5
movq %fs:0x0, %rax
leaq -0x1a8(%rax), %rax
leaq 0x4fb28(%rip), %rcx     # 0x577c0
movq %rcx, (%rax)
movq %fs:0x0, %rax
leaq -0x1b8(%rax), %rax
leaq 0x2eece(%rip), %rcx     # 0x36b80
movq %rcx, (%rax)
movq %fs:0x0, %rax
leaq -0x1b0(%rax), %rax
leaq 0x2eee4(%rip), %rcx     # 0x36bb0
movq %rcx, (%rax)
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq %rax, %rdi
callq 0x7030