Python time.process_time() Examples

The following are 30 code examples of time.process_time(). 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 also want to check out all available functions/classes of the module time , or try the search function .
Example #1
Source File: test_regex.py    From zmirror with 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
Source File: runner.py    From eventsourcing with 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 #3
Source File: stratiWedge.py    From badlands with GNU General Public License v3.0 6 votes vote down vote up
def update_layers(self, erosion, deposition, elev, verbose=False):
        """
        This function updates the stratigraphic layers based active layer composition.

        Args:
            erosion: value of the erosion for the given points (m)
            deposition: value of the deposition for the given point (m)
            elev: numpy float-type array containing Z coordinates of the local TIN nodes.
            verbose : (bool) when :code:`True`, output additional debug information (default: :code:`False`).
        """

        time0 = time.process_time()
        newH, newS = pdalgo.updatestrati(self.depoThick[:,:self.step+1,:], self.layerThick[:,:self.step+1],
                                    erosion, deposition)

        self.depoThick[:,:self.step+1,:] = newS
        self.layerThick[:,:self.step+1] = newH
        self.paleoDepth[:,self.step] = elev

        if verbose:
            print("   - Update erosion/deposition ", time.process_time() - time0)

        return 
Example #4
Source File: solvers.py    From pysat with 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 #5
Source File: solvers.py    From pysat with 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 #6
Source File: solvers.py    From pysat with 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 #7
Source File: solvers.py    From pysat with 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 #8
Source File: solvers.py    From pysat with 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 #9
Source File: solvers.py    From pysat with 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 #10
Source File: solvers.py    From pysat with 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 #11
Source File: solvers.py    From pysat with 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 #12
Source File: solvers.py    From pysat with 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 #13
Source File: solvers.py    From pysat with 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 #14
Source File: solvers.py    From pysat with 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 #15
Source File: solvers.py    From pysat with 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 #16
Source File: solvers.py    From pysat with 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 #17
Source File: solvers.py    From pysat with 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 #18
Source File: solvers.py    From pysat with 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 #19
Source File: solvers.py    From pysat with 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 #20
Source File: solvers.py    From pysat with 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 #21
Source File: solvers.py    From pysat with 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 #22
Source File: solvers.py    From pysat with 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 #23
Source File: test_time.py    From Fluid-Designer with 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 #24
Source File: profile.py    From Imogen with 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 #25
Source File: test_time.py    From ironpython3 with 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 #26
Source File: carbMesh.py    From badlands with 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 #27
Source File: carbMesh.py    From badlands with 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 
Example #28
Source File: carbMesh.py    From badlands with GNU General Public License v3.0 6 votes vote down vote up
def update_layers(self, clastic, elev, verbose=False):
        """
        This function updates the stratigraphic layers.

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

        time0 = time.process_time()
        newH, newS = pdalgo.stratcarb(self.depoThick[:,:self.step+1,:], self.layerThick[:,:self.step+1],
                                    clastic)
        self.depoThick[:,:self.step+1,:] = newS[:,:self.step+1,:]
        self.layerThick[:,:self.step+1] = newH[:,:self.step+1]
        self.paleoDepth[:,self.step] = elev

        if verbose:
            print("   - Update erosion/deposition ", time.process_time() - time0)

        return 
Example #29
Source File: stratiWedge.py    From badlands with 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.alayR = pdalgo.getactlay(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
Source File: zmirror.py    From zmirror with 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