Python time.process_time() Examples

The following are 30 code examples for showing how to use time.process_time(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module time , or try the search function .

Example 1
Project: zmirror   Author: aploium   File: test_regex.py    License: MIT License 7 votes vote down vote up
def performance_test__regex_basic_mirrorlization(self):
        """对 regex_basic_mirrorlization 进行性能测试"""
        from more_configs.config_google_and_zhwikipedia import target_domain, external_domains
        self.reload_zmirror(configs_dict=dict(
            target_domain=target_domain,
            external_domains=external_domains,
        ))
        from time import process_time
        reg_func = self.zmirror.response_text_basic_mirrorlization
        print(self.zmirror.regex_basic_mirrorlization.pattern)

        with open(zmirror_file("tests/sample/google_home.html"), "r", encoding="utf-8") as fp:
            text = fp.read()

        start_time = process_time()
        for _ in range(1000):
            reg_func(text)
        print("100x google_home.html", process_time() - start_time) 
Example 2
Project: zmirror   Author: aploium   File: zmirror.py    License: MIT License 6 votes vote down vote up
def generate_our_response():
    """
    生成我们的响应
    :rtype: Response
    """
    # copy and parse remote response
    resp = copy_response(is_streamed=parse.streamed_our_response)

    if parse.time["req_time_header"] >= 0.00001:
        parse.set_extra_resp_header('X-Header-Req-Time', "%.4f" % parse.time["req_time_header"])
    if parse.time.get("start_time") is not None and not parse.streamed_our_response:
        # remote request time should be excluded when calculating total time
        parse.set_extra_resp_header('X-Body-Req-Time', "%.4f" % parse.time["req_time_body"])
        parse.set_extra_resp_header('X-Compute-Time',
                                    "%.4f" % (process_time() - parse.time["start_time"]))

    parse.set_extra_resp_header('X-Powered-By', 'zmirror/%s' % CONSTS.__VERSION__)

    if developer_dump_all_traffics and not parse.streamed_our_response:
        dump_zmirror_snapshot("traffic")

    return resp 
Example 3
Project: eventsourcing   Author: johnbywater   File: runner.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def run(self) -> None:
        while not self.stop_event.is_set():

            try:
                self.fetch_barrier.wait()
                self.execute_barrier.wait()
                self.execute_barrier.wait()
                self.call_commands()
            except BrokenBarrierError:
                self.fetch_barrier.abort()
                self.execute_barrier.abort()
                self.stop_event.set()
            else:
                tick_time = time.time()
                process_time = time.process_time()
                if self.last_tick_time:
                    self.do_tick(process_time, tick_time)

                self.last_tick_time = tick_time
                self.last_process_time = process_time
                self.tick_count += 1

                if self.tick_interval:
                    sleep_interval = self.tick_interval - self.tick_adjustment
                    sleep(max(sleep_interval, 0)) 
Example 4
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve(self, assumptions=[]):
        """
            Solve internal formula.
        """

        if self.cadical:
            if self.use_timer:
                start_time = process_time()

            self.status = pysolvers.cadical_solve(self.cadical, assumptions,
                    int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            self.prev_assumps = assumptions
            return self.status 
Example 5
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve(self, assumptions=[]):
        """
            Solve internal formula.
        """

        if self.glucose:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.glucose3_solve(self.glucose, assumptions,
                    int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 6
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve_limited(self, assumptions=[]):
        """
            Solve internal formula using given budgets for conflicts and
            propagations.
        """

        if self.glucose:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.glucose3_solve_lim(self.glucose,
                    assumptions, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 7
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def propagate(self, assumptions=[], phase_saving=0):
        """
            Propagate a given set of assumption literals.
        """

        if self.glucose:
            if self.use_timer:
                 start_time = process_time()

            st, props = pysolvers.glucose3_propagate(self.glucose,
                    assumptions, phase_saving, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return bool(st), props if props != None else [] 
Example 8
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve(self, assumptions=[]):
        """
            Solve internal formula.
        """

        if self.glucose:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.glucose41_solve(self.glucose, assumptions,
                    int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 9
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def propagate(self, assumptions=[], phase_saving=0):
        """
            Propagate a given set of assumption literals.
        """

        if self.glucose:
            if self.use_timer:
                 start_time = process_time()

            st, props = pysolvers.glucose41_propagate(self.glucose,
                    assumptions, phase_saving, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return bool(st), props if props != None else [] 
Example 10
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve(self, assumptions=[]):
        """
            Solve internal formula.
        """

        if self.lingeling:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.lingeling_solve(self.lingeling,
                    assumptions, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            self.prev_assumps = assumptions
            return self.status 
Example 11
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve(self, assumptions=[]):
        """
            Solve internal formula.
        """

        if self.maplesat:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.maplechrono_solve(self.maplesat,
                    assumptions, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 12
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve_limited(self, assumptions=[]):
        """
            Solve internal formula using given budgets for conflicts and
            propagations.
        """

        if self.maplesat:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.maplechrono_solve_lim(self.maplesat,
                    assumptions, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 13
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def propagate(self, assumptions=[], phase_saving=0):
        """
            Propagate a given set of assumption literals.
        """

        if self.maplesat:
            if self.use_timer:
                 start_time = process_time()

            st, props = pysolvers.maplechrono_propagate(self.maplesat,
                    assumptions, phase_saving, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return bool(st), props if props != None else [] 
Example 14
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve_limited(self, assumptions=[]):
        """
            Solve internal formula using given budgets for conflicts and
            propagations.
        """

        if self.maplesat:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.maplecm_solve_lim(self.maplesat,
                    assumptions, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 15
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def propagate(self, assumptions=[], phase_saving=0):
        """
            Propagate a given set of assumption literals.
        """

        if self.maplesat:
            if self.use_timer:
                 start_time = process_time()

            st, props = pysolvers.maplecm_propagate(self.maplesat,
                    assumptions, phase_saving, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return bool(st), props if props != None else [] 
Example 16
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve(self, assumptions=[]):
        """
            Solve internal formula.
        """

        if self.maplesat:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.maplesat_solve(self.maplesat, assumptions,
                    int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 17
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve_limited(self, assumptions=[]):
        """
            Solve internal formula using given budgets for conflicts and
            propagations.
        """

        if self.maplesat:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.maplesat_solve_lim(self.maplesat,
                    assumptions, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 18
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def propagate(self, assumptions=[], phase_saving=0):
        """
            Propagate a given set of assumption literals.
        """

        if self.maplesat:
            if self.use_timer:
                 start_time = process_time()

            st, props = pysolvers.maplesat_propagate(self.maplesat,
                    assumptions, phase_saving, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return bool(st), props if props != None else [] 
Example 19
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve_limited(self, assumptions=[]):
        """
            Solve internal formula using given budgets for conflicts and
            propagations.
        """

        if self.minicard:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.minicard_solve_lim(self.minicard,
                    assumptions, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 20
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def propagate(self, assumptions=[], phase_saving=0):
        """
            Propagate a given set of assumption literals.
        """

        if self.minicard:
            if self.use_timer:
                 start_time = process_time()

            st, props = pysolvers.minicard_propagate(self.minicard,
                    assumptions, phase_saving, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return bool(st), props if props != None else [] 
Example 21
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve(self, assumptions=[]):
        """
            Solve internal formula.
        """

        if self.minisat:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.minisat22_solve(self.minisat, assumptions,
                    int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 22
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve_limited(self, assumptions=[]):
        """
            Solve internal formula using given budgets for conflicts and
            propagations.
        """

        if self.minisat:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.minisat22_solve_lim(self.minisat,
                    assumptions, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 23
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def propagate(self, assumptions=[], phase_saving=0):
        """
            Propagate a given set of assumption literals.
        """

        if self.minisat:
            if self.use_timer:
                 start_time = process_time()

            st, props = pysolvers.minisat22_propagate(self.minisat,
                    assumptions, phase_saving, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return bool(st), props if props != None else [] 
Example 24
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def solve_limited(self, assumptions=[]):
        """
            Solve internal formula using given budgets for conflicts and
            propagations.
        """

        if self.minisat:
            if self.use_timer:
                 start_time = process_time()

            self.status = pysolvers.minisatgh_solve_lim(self.minisat,
                    assumptions, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return self.status 
Example 25
Project: pysat   Author: pysathq   File: solvers.py    License: MIT License 6 votes vote down vote up
def propagate(self, assumptions=[], phase_saving=0):
        """
            Propagate a given set of assumption literals.
        """

        if self.minisat:
            if self.use_timer:
                 start_time = process_time()

            st, props = pysolvers.minisatgh_propagate(self.minisat,
                    assumptions, phase_saving, int(MainThread.check()))

            if self.use_timer:
                self.call_time = process_time() - start_time
                self.accu_time += self.call_time

            return bool(st), props if props != None else [] 
Example 26
Project: Fluid-Designer   Author: Microvellum   File: test_time.py    License: GNU General Public License v3.0 6 votes vote down vote up
def test_get_clock_info(self):
        clocks = ['clock', 'perf_counter', 'process_time', 'time']
        if hasattr(time, 'monotonic'):
            clocks.append('monotonic')

        for name in clocks:
            info = time.get_clock_info(name)
            #self.assertIsInstance(info, dict)
            self.assertIsInstance(info.implementation, str)
            self.assertNotEqual(info.implementation, '')
            self.assertIsInstance(info.monotonic, bool)
            self.assertIsInstance(info.resolution, float)
            # 0.0 < resolution <= 1.0
            self.assertGreater(info.resolution, 0.0)
            self.assertLessEqual(info.resolution, 1.0)
            self.assertIsInstance(info.adjustable, bool)

        self.assertRaises(ValueError, time.get_clock_info, 'xxx') 
Example 27
Project: Imogen   Author: CedricGuillemet   File: profile.py    License: MIT License 6 votes vote down vote up
def trace_dispatch(self, frame, event, arg):
        timer = self.timer
        t = timer()
        t = t[0] + t[1] - self.t - self.bias

        if event == "c_call":
            self.c_func_name = arg.__name__

        if self.dispatch[event](self, frame,t):
            t = timer()
            self.t = t[0] + t[1]
        else:
            r = timer()
            self.t = r[0] + r[1] - t # put back unrecorded delta

    # Dispatch routine for best timer program (return = scalar, fastest if
    # an integer but float works too -- and time.process_time() relies on that). 
Example 28
Project: ironpython3   Author: IronLanguages   File: test_time.py    License: Apache License 2.0 6 votes vote down vote up
def test_get_clock_info(self):
        clocks = ['clock', 'perf_counter', 'process_time', 'time']
        if hasattr(time, 'monotonic'):
            clocks.append('monotonic')

        for name in clocks:
            info = time.get_clock_info(name)
            #self.assertIsInstance(info, dict)
            self.assertIsInstance(info.implementation, str)
            self.assertNotEqual(info.implementation, '')
            self.assertIsInstance(info.monotonic, bool)
            self.assertIsInstance(info.resolution, float)
            # 0.0 < resolution <= 1.0
            self.assertGreater(info.resolution, 0.0)
            self.assertLessEqual(info.resolution, 1.0)
            self.assertIsInstance(info.adjustable, bool)

        self.assertRaises(ValueError, time.get_clock_info, 'xxx') 
Example 29
Project: badlands   Author: badlands-model   File: carbMesh.py    License: GNU General Public License v3.0 6 votes vote down vote up
def get_active_layer(self, actlay, verbose=False):
        """
        This function extracts the active layer based on the underlying stratigraphic architecture.

        Args:
            actlay : active layer elevation based on nodes elevation (m).
            verbose : (bool) when :code:`True`, output additional debug information (default: :code:`False`).
        """

        time0 = time.process_time()
        self.alay = pdalgo.getactlay2(actlay, self.layerThick[:,:self.step+1],
                                    self.depoThick[:,:self.step+1,:])
        if verbose:
            print("   - Get active layer composition ", time.process_time() - time0)
            time0 = time.process_time()

        return 
Example 30
Project: badlands   Author: badlands-model   File: carbMesh.py    License: GNU General Public License v3.0 6 votes vote down vote up
def update_active_layer(self, actlayer, elev, verbose=False):
        """
        This function updates the stratigraphic layers based active layer composition.

        Args:
            actlay : active layer elevation based on nodes elevation (m).
            elev : elevation values for TIN nodes.
            verbose : (bool) when :code:`True`, output additional debug information (default: :code:`False`).
        """

        time0 = time.process_time()
        ero = actlayer[:,0]-self.alay[:,0]
        ero[ero>0.] = 0.
        depo = actlayer[:,0]-self.alay[:,0]
        depo[depo<0.] = 0.
        newH, newS = pdalgo.updatecstrati(self.depoThick[:,:self.step+1,:],
                                    self.layerThick[:,:self.step+1], ero, depo)
        self.depoThick[:,:self.step+1,0] = newS
        self.layerThick[:,:self.step+1] = newH
        self.paleoDepth[:,self.step] = elev

        if verbose:
            print("   - Update active layer due to wave-induced erosion/deposition ", time.process_time() - time0)

        return