def main():
    (opts, _) = ParseOptions()
    lock = locking.SharedLock('TestLock')
    state = State(opts.thread_count)
    lock.acquire(shared=0)
    try:
        for i in range(opts.thread_count):
            t = threading.Thread(target=_Counter, args=(lock, state, i))
            t.setDaemon(True)
            t.start()
        start = time.clock()
    finally:
        lock.release()
    while True:
        if ((time.clock() - start) > opts.duration):
            break
        time.sleep(0.1)
    lock.acquire(shared=0)
    lock_cputime = (time.clock() - start)
    res = resource.getrusage(resource.RUSAGE_SELF)
    print(('Total number of acquisitions: %s' % state.total_count))
    print('Per-thread acquisitions:')
    for (i, count) in enumerate(state.counts):
        print(('  Thread %s: %d (%0.1f%%)' % (i, count, ((100.0 * count) / state.total_count))))
    print(('Benchmark CPU time: %0.3fs' % lock_cputime))
    print(('Average time per lock acquisition: %0.5fms' % ((1000.0 * lock_cputime) / state.total_count)))
    print('Process:')
    print(('  User time: %0.3fs' % res.ru_utime))
    print(('  System time: %0.3fs' % res.ru_stime))
    print(('  Total time: %0.3fs' % (res.ru_utime + res.ru_stime)))
    os._exit(0)
def main():
    (opts, _) = ParseOptions()
    lock = locking.SharedLock('TestLock')
    state = State(opts.thread_count)
    lock.acquire(shared=0)
    try:
        for i in range(opts.thread_count):
            t = threading.Thread(target=_Counter, args=(lock, state, i))
            t.setDaemon(True)
            t.start()
        start = time.clock()
    finally:
        lock.release()
    while True:
        if ((time.clock() - start) > opts.duration):
            break
        time.sleep(0.1)
    lock.acquire(shared=0)
    lock_cputime = (time.clock() - start)
    res = resource.getrusage(resource.RUSAGE_SELF)
    print(('Total number of acquisitions: %s' % state.total_count))
    print('Per-thread acquisitions:')
    for (i, count) in enumerate(state.counts):
        print(('  Thread %s: %d (%0.1f%%)' % (i, count, ((100.0 * count) / state.total_count))))
    print(('Benchmark CPU time: %0.3fs' % lock_cputime))
    print(('Average time per lock acquisition: %0.5fms' % ((1000.0 * lock_cputime) / state.total_count)))
    print('Process:')
    print(('  User time: %0.3fs' % res.ru_utime))
    print(('  System time: %0.3fs' % res.ru_stime))
    print(('  Total time: %0.3fs' % (res.ru_utime + res.ru_stime)))
    os._exit(0)