// File: /workspace/github_cpp_makefile_star2_O1/chahk0129[P]hash_bench/./bench/benchmark.hpp
// Function: benchmark_t<char [32]>::mixed(int, Pair<char [32]>*, int, int)
inline void benchmark_t<Key_t>::mixed(int index_type, Pair<Key_t>* init_kv, int init_num, int num_threads){
    Hash<Key_t>* hashtable = getInstance<Key_t>(index_type);
    gen_input(init_kv, init_num);
    std::random_shuffle(init_kv, init_kv+init_num);

    int warmup = init_num/2;
    std::cout << "warming up ... "; 
    for(int i=0; i<warmup; i++){
	hashtable->Insert(init_kv[i].key, init_kv[i].value);
    }
    std::cout << "Done!" << std::endl;

    int insert_ratio = 15;
    int search_ratio = 50;
    int delete_ratio = 10;
    int update_ratio = 25;

    auto mixed_func = [&hashtable, &init_kv, warmup, insert_ratio, search_ratio, delete_ratio, update_ratio, num_threads](int thread_id, bool){
	size_t chunk = warmup / num_threads;
	size_t from = chunk * thread_id;
	size_t to = chunk * (thread_id + 1);
	int insert_idx = warmup + from;
	int search_idx = from;

	for(int i=from; i<to; i+=1000){
	    int r = rand() % 100;
	    if(r < insert_ratio){
		for(int j=insert_idx; j<insert_idx+1000; j++)
		    hashtable->Insert(init_kv[j].key, init_kv[j].value);
		insert_idx += 1000;
	    }
	    else if(r < insert_ratio+search_ratio){
		for(int j=search_idx; j<search_idx+1000; j++)
		    auto ret = hashtable->Get(init_kv[j].key);
		search_idx += 1000;
	    }
	    else if(r < insert_ratio+search_ratio+update_ratio){
		for(int j=search_idx; j<search_idx+1000; j++)
		    auto ret = hashtable->Update(init_kv[j].key, init_kv[j].value);
		search_idx += 1000;
	    }
	    else{
		for(int j=search_idx; j<search_idx+1000; j++)
		    auto ret = hashtable->Delete(init_kv[j].key);
		search_idx += 1000;
	    }
	}
    };

    clear_cache();
    double start_time = get_now();
    start_threads(hashtable, num_threads, mixed_func, false);
    double end_time = get_now();

    double throughput = warmup / (end_time - start_time) / 1000000; // MOps/sec
    std::cout << "\033[1;32m";
    std::cout << "Throughput(MOps/sec)" << throughput << "\033[0m" << std::endl;
    std::cout << "Insert(10%), Search(50%), Delete(10%), Update(25%)" << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, %ebp
movl %ecx, %r14d
movl %esi, %edi
movq %rdx, 0x8(%rsp)
callq 0x825d
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rdi
movl %r14d, %esi
callq 0x8316
cmpl $0x2, %r14d
jb 0x7d23
movq 0x8(%rsp), %rbx
movslq %r14d, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %r15
movl $0x28, %r12d
movabsq $-0x3333333333333333, %r13 # imm = 0xCCCCCCCCCCCCCCCD
callq 0x2060
cltq
movq %r12, %rcx
sarq $0x3, %rcx
imulq %r13, %rcx
incq %rcx
cqto
idivq %rcx
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %rax
cmpq %rax, %r12
je 0x7d16
leaq (%rbx,%r12), %rcx
addq %rbx, %rax
movq 0x20(%rcx), %rdx
movq %rdx, 0x50(%rsp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq 0x20(%rax), %rdx
movq %rdx, 0x20(%rcx)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0x50(%rsp), %rcx
movq %rcx, 0x20(%rax)
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
addq $0x28, %r12
cmpq %r12, %r15
jne 0x7c9e
movl %r14d, %r12d
shrl $0x1f, %r12d
addl %r14d, %r12d
sarl %r12d
movq 0xc289(%rip), %rbx      # 0x13fc0
leaq 0x570d(%rip), %rsi      # 0xd44b
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2210
cmpl $0x2, %r14d
jl 0x7d77
movl %r12d, %r14d
xorl %r15d, %r15d
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x20(%rsi,%r15), %rdx
addq %r15, %rsi
movq (%rdi), %rax
callq *(%rax)
addq $0x28, %r15
decq %r14
jne 0x7d57
leaq 0x56dd(%rip), %rsi      # 0xd45b
movl $0x5, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x18(%rsp), %r13
leaq 0x30(%rsp), %r14
movq %r13, (%r14)
leaq 0x8(%rsp), %rax
movq %rax, 0x8(%r14)
movl %r12d, 0x10(%r14)
movaps 0x525d(%rip), %xmm0     # 0xd030
movups %xmm0, 0x14(%r14)
movl %ebp, 0x24(%r14)
leaq 0x20(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x22e0
xorps %xmm0, %xmm0
cvtsi2sdq (%r15), %xmm0
cvtsi2sdq 0x8(%r15), %xmm2
divsd 0x5257(%rip), %xmm2     # 0xd058
addsd %xmm0, %xmm2
movsd %xmm2, 0x10(%rsp)
movq (%r13), %rdi
movslq %ebp, %rsi
movb $0x0, (%r15)
leaq 0x20(%rsp), %rcx
movq %r14, %rdx
callq 0xcbc2
leaq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x22e0
xorps %xmm0, %xmm0
cvtsi2sdq (%r14), %xmm0
xorps %xmm1, %xmm1
cvtsi2sdq 0x8(%r14), %xmm1
movsd 0x520d(%rip), %xmm2     # 0xd058
divsd %xmm2, %xmm1
addsd %xmm0, %xmm1
subsd 0x10(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
divsd %xmm1, %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x53a7(%rip), %rsi      # 0xd21d
movl $0x7, %edx
movq %rbx, %rdi
callq 0x2210
leaq 0x55d7(%rip), %rsi      # 0xd461
movl $0x14, %edx
movq %rbx, %rdi
callq 0x2210
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x22d0
movq %rax, %r14
leaq 0x53a8(%rip), %rsi      # 0xd257
movl $0x4, %edx
movq %rax, %rdi
callq 0x2210
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x558c(%rip), %rsi      # 0xd476
movl $0x32, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2120
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop