示例#1
0
        def main(libc_name, n):
            import time
            from threading import Thread
            from _ffi import CDLL, types
            #
            libc = CDLL(libc_name)
            sleep = libc.getfunc('sleep', [types.uint], types.uint)
            delays = [0] * n + [1]

            #
            def loop_of_sleeps(i, delays):
                for delay in delays:
                    sleep(delay)  # ID: sleep

            #
            threads = [
                Thread(target=loop_of_sleeps, args=[i, delays])
                for i in range(5)
            ]
            start = time.time()
            for i, thread in enumerate(threads):
                thread.start()
            for thread in threads:
                thread.join()
            end = time.time()
            return end - start
示例#2
0
        def main(libm_name):
            try:
                from _ffi import CDLL, types
            except ImportError:
                sys.stderr.write('SKIP: cannot import _ffi\n')
                return 0

            libm = CDLL(libm_name)
            pow = libm.getfunc('pow', [types.double, types.double],
                               types.double)
            i = 0
            res = 0
            while i < 300:
                tmp = pow(2, 3)   # ID: fficall
                res += tmp
                i += 1
            return pow.getaddr(), res
示例#3
0
 def main(libc_name, n):
     import time
     from threading import Thread
     from _ffi import CDLL, types
     #
     libc = CDLL(libc_name)
     sleep = libc.getfunc('sleep', [types.uint], types.uint)
     delays = [0]*n + [1]
     #
     def loop_of_sleeps(i, delays):
         for delay in delays:
             sleep(delay)    # ID: sleep
     #
     threads = [Thread(target=loop_of_sleeps, args=[i, delays]) for i in range(5)]
     start = time.time()
     for i, thread in enumerate(threads):
         thread.start()
     for thread in threads:
         thread.join()
     end = time.time()
     return end - start