// File: dustin[P]kvtest/tests.cc
// Function: EnduranceTest::run(kvtest::KVStore*)
bool EnduranceTest::run(KVStore *tut) {
    long i = 0, prev_calls = 0;
    CountingCallback cb;
    time_t start = time(NULL);
    time_t step = time(NULL);
    const int alarm_freq = 10;
    Keys k(30000);
    Values v(20, 40000, 60000);

    setup_alarm(alarm_freq);

    std::cout << "# start time:  " << start << std::endl;
    std::cout << "# cmds\tbacklog\ttime\tabstime\trate" << std::endl;

    for(i = 0 ; ; i++) {
        std::string key(k.nextKey());
        const char *value = v.nextValue();

        tut->set(key, value, cb);
        if (alarmed) {
            time_t now = time(NULL);
            int delta = (int)(now - step);
            long new_calls = i - prev_calls;
            step = now;
            std::cout << i << "\t" << (i - cb.num_calls() + 1)
                      << "\t" << delta << "\t" << now << "\t"
                      << ((double)new_calls / (double)delta) << std::endl
                      << std::flush;
            prev_calls = i;
            setup_alarm(alarm_freq);
        }
    }

    // Last one to wait for a commit.
    RememberingCallback<bool> cbLast;
    tut->noop(cbLast);
    cbLast.waitForValue();
    time_t end = time(NULL);

    assertEquals((int)i, cb.num_calls());

    int delta = (int)(end - start);
    std::cout << "Ran " << i << " operations in "
              << delta << "s ("
              << (i/delta) << " ops/s)"
              << std::endl;
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x74b0
xorl %eax, %eax
movl %eax, %edi
movq %rdi, -0x188(%rbp)
callq 0x3260
movq -0x188(%rbp), %rdi
movq %rax, -0x60(%rbp)
callq 0x3260
movq %rax, -0x68(%rbp)
movl $0xa, -0x6c(%rbp)
leaq -0x90(%rbp), %rdi
movl $0x7530, %esi           # imm = 0x7530
callq 0x8e30
jmp 0x696a
leaq -0xc0(%rbp), %rdi
movl $0x14, %esi
movl $0x9c40, %edx           # imm = 0x9C40
movl $0xea60, %ecx           # imm = 0xEA60
callq 0x9c60
jmp 0x6987
movl $0xa, %edi
callq 0x68b0
jmp 0x6993
movq 0xe626(%rip), %rdi      # 0x14fc0
leaq 0x77cc(%rip), %rsi      # 0xe16d
callq 0x3280
movq %rax, -0x190(%rbp)
jmp 0x69af
movq -0x190(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x3490
movq %rax, -0x198(%rbp)
jmp 0x69c8
movq -0x198(%rbp), %rdi
movq 0xe5d2(%rip), %rsi      # 0x14fa8
callq 0x32c0
jmp 0x69dd
movq 0xe5dc(%rip), %rdi      # 0x14fc0
leaq 0x7792(%rip), %rsi      # 0xe17d
callq 0x3280
movq %rax, -0x1a0(%rbp)
jmp 0x69f9
movq -0x1a0(%rbp), %rdi
movq 0xe5a1(%rip), %rsi      # 0x14fa8
callq 0x32c0
jmp 0x6a0e
movq $0x0, -0x18(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x9050
movq %rax, -0x1a8(%rbp)
jmp 0x6a2b
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x3460
movq -0x1a8(%rbp), %rsi
movq -0x1b0(%rbp), %rdx
leaq -0xe0(%rbp), %rdi
callq 0x5140
jmp 0x6a5a
leaq -0xe1(%rbp), %rdi
callq 0x32e0
leaq -0xc0(%rbp), %rdi
callq 0x9ef0
movq %rax, -0x1b8(%rbp)
jmp 0x6a7b
movq -0x1b8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rdi
movq -0xf0(%rbp), %rdx
movq (%rdi), %rax
movq 0x28(%rax), %rax
leaq -0xe0(%rbp), %rsi
leaq -0x58(%rbp), %rcx
callq *%rax
jmp 0x6aaa
testb $0x1, 0xe80a(%rip)      # 0x152bb
je 0x6ceb
xorl %eax, %eax
movl %eax, %edi
callq 0x3260
movq %rax, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
movl -0x68(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0xfc(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x108(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rsi
movq 0xe4c0(%rip), %rdi      # 0x14fc0
callq 0x3490
movq %rax, -0x1c0(%rbp)
jmp 0x6b0e
movq -0x1c0(%rbp), %rdi
leaq 0x7682(%rip), %rsi      # 0xe19e
callq 0x3280
movq %rax, -0x1c8(%rbp)
jmp 0x6b2a
movq -0x18(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x76b0
movl %eax, -0x1cc(%rbp)
jmp 0x6b46
movq -0x1c8(%rbp), %rdi
movq -0x1d8(%rbp), %rsi
movl -0x1cc(%rbp), %eax
cltq
subq %rax, %rsi
incq %rsi
callq 0x3490
movq %rax, -0x1e0(%rbp)
jmp 0x6b70
movq -0x1e0(%rbp), %rdi
leaq 0x7620(%rip), %rsi      # 0xe19e
callq 0x3280
movq %rax, -0x1e8(%rbp)
jmp 0x6b8c
movq -0x1e8(%rbp), %rdi
movl -0xfc(%rbp), %esi
callq 0x3440
movq %rax, -0x1f0(%rbp)
jmp 0x6ba7
movq -0x1f0(%rbp), %rdi
leaq 0x75e9(%rip), %rsi      # 0xe19e
callq 0x3280
movq %rax, -0x1f8(%rbp)
jmp 0x6bc3
movq -0x1f8(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x3490
movq %rax, -0x200(%rbp)
jmp 0x6bdf
movq -0x200(%rbp), %rdi
leaq 0x75b1(%rip), %rsi      # 0xe19e
callq 0x3280
movq %rax, -0x208(%rbp)
jmp 0x6bfb
movq -0x208(%rbp), %rdi
cvtsi2sdq -0x108(%rbp), %xmm0
cvtsi2sdl -0xfc(%rbp), %xmm1
divsd %xmm1, %xmm0
callq 0x34c0
movq %rax, -0x210(%rbp)
jmp 0x6c25
movq -0x210(%rbp), %rdi
movq 0xe375(%rip), %rsi      # 0x14fa8
callq 0x32c0
movq %rax, -0x218(%rbp)
jmp 0x6c41
movq -0x218(%rbp), %rdi
movq 0xe379(%rip), %rsi      # 0x14fc8
callq 0x32c0
jmp 0x6c56
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0xa, %edi
callq 0x68b0
jmp 0x6c6a
jmp 0x6ceb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x6d20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x6d14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x6d08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xe1(%rbp), %rdi
callq 0x32e0
jmp 0x6d08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x3160
jmp 0x6d08
leaq -0xe0(%rbp), %rdi
callq 0x3160
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x6a16
leaq -0xc0(%rbp), %rdi
callq 0x9e70
leaq -0x90(%rbp), %rdi
callq 0x8fd0
leaq -0x58(%rbp), %rdi
callq 0x76f0
movq -0x98(%rbp), %rdi
callq 0x3450
nopw %cs:(%rax,%rax)