// File: suyash[P]chan/misc/promise_speed_test_threads.cc
// Function: measure(int)
void measure(int numThreads) {
	int pain = static_cast<int>(std::log2(numThreads));
	for (int i = 0; i < numThreads; i++) {
		serverThreads[i] = std::async(std::launch::async, server, promises[pain][i], i);
		clientThreads[i] = std::async(std::launch::async, client, promises[pain][i], i);
	}

	for (int i = 0; i < numThreads; i++) {
		serverThreads[i].wait();
		clientThreads[i].wait();
	}

	auto smallestStart = startTimes[0];
	for (int i = 1; i < numThreads; i++) {
		if (startTimes[i] < smallestStart) {
			smallestStart = startTimes[i];
		}
	}

	auto largestEnd = endTimes[0];
	for (int i = 1; i < numThreads; i++) {
		if (endTimes[i] > largestEnd) {
			largestEnd = endTimes[i];
		}
	}

	uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(
	                  largestEnd - smallestStart)
	                  .count();

#ifdef __APPLE__
	printf(
	    "promise: %d*%d send/recv time in ms: %lld (%f nr_of_msg/msec)\n",
	    numThreads, RUN_SIZE, ms, double(numThreads * RUN_SIZE) / ms);
#else
	printf(
	    "promise: %d*%d send/recv time in ms: %ld (%f nr_of_msg/msec)\n",
	    numThreads, RUN_SIZE, ms, double(numThreads * RUN_SIZE) / ms);
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x4(%rbp)
movl -0x4(%rbp), %edi
callq 0x3c70
cvttsd2si %xmm0, %eax
movl %eax, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x37cb
movslq -0x8(%rbp), %rax
leaq 0x10a88(%rip), %rcx     # 0x14190
imulq $0x493e00, %rax, %rax   # imm = 0x493E00
addq %rax, %rcx
movslq -0xc(%rbp), %rax
imulq $0x493e0, %rax, %rax    # imm = 0x493E0
addq %rax, %rcx
leaq -0x20(%rbp), %rdi
movl $0x1, %esi
leaq -0x180(%rip), %rdx      # 0x35b0
leaq -0xc(%rbp), %r8
callq 0x3c90
movslq -0xc(%rbp), %rax
leaq 0x16f404c(%rip), %rdi   # 0x16f7790
shlq $0x4, %rax
addq %rax, %rdi
leaq -0x20(%rbp), %rsi
callq 0x3e60
leaq -0x20(%rbp), %rdi
callq 0x3ae0
movslq -0x8(%rbp), %rax
leaq 0x10a28(%rip), %rcx     # 0x14190
imulq $0x493e00, %rax, %rax   # imm = 0x493E00
addq %rax, %rcx
movslq -0xc(%rbp), %rax
imulq $0x493e0, %rax, %rax    # imm = 0x493E0
addq %rax, %rcx
leaq -0x30(%rbp), %rdi
movl $0x1, %esi
leaq -0x130(%rip), %rdx      # 0x3660
leaq -0xc(%rbp), %r8
callq 0x3c90
movslq -0xc(%rbp), %rax
leaq 0x16f40ec(%rip), %rdi   # 0x16f7890
shlq $0x4, %rax
addq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x3e60
leaq -0x30(%rbp), %rdi
callq 0x3ae0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x36f1
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x3813
movslq -0x34(%rbp), %rax
leaq 0x16f3fab(%rip), %rdi   # 0x16f7790
shlq $0x4, %rax
addq %rax, %rdi
callq 0x3eb0
movslq -0x34(%rbp), %rax
leaq 0x16f4094(%rip), %rdi   # 0x16f7890
shlq $0x4, %rax
addq %rax, %rdi
callq 0x3eb0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x37d2
movq 0x16f4176(%rip), %rax   # 0x16f7990
movq %rax, -0x40(%rbp)
movl $0x1, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x386e
movslq -0x44(%rbp), %rax
leaq 0x16f4158(%rip), %rdi   # 0x16f7990
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x40(%rbp), %rsi
callq 0x3ee0
testb $0x1, %al
jne 0x384e
jmp 0x3861
movslq -0x44(%rbp), %rcx
leaq 0x16f4137(%rip), %rax   # 0x16f7990
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
jmp 0x3863
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3825
movq 0x16f419b(%rip), %rax   # 0x16f7a10
movq %rax, -0x50(%rbp)
movl $0x1, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x38c9
movslq -0x54(%rbp), %rax
leaq 0x16f417d(%rip), %rdi   # 0x16f7a10
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x50(%rbp), %rsi
callq 0x3f20
testb $0x1, %al
jne 0x38a9
jmp 0x38bc
movslq -0x54(%rbp), %rcx
leaq 0x16f415c(%rip), %rax   # 0x16f7a10
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
jmp 0x38be
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x3880
leaq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3f80
movq %rax, -0x70(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3f50
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3fd0
movq %rax, -0x60(%rbp)
movl -0x4(%rbp), %esi
movq -0x60(%rbp), %rcx
imull $0x30d4, %esi, %eax     # imm = 0x30D4
cvtsi2sd %eax, %xmm0
movq %rcx, %xmm1
movaps 0x86ff(%rip), %xmm2     # 0xc010
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x8703(%rip), %xmm2     # 0xc020
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x8769(%rip), %rdi      # 0xc0a0
movl $0x30d4, %edx           # imm = 0x30D4
movb $0x1, %al
callq 0x3030
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)