python类process_time()的实例源码

foregrounds.py 文件源码 项目:fg21sim 作者: liweitianux 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def simulate_component(self, compID):
        """
        Do simulation for the specified foreground component.
        """
        logger.info("==================================================")
        logger.info(">>> Simulate component: %s <<<" % compID)
        logger.info("==================================================")
        t1_start = time.perf_counter()
        t2_start = time.process_time()

        comp_cls = COMPONENTS_ALL[compID]
        comp_obj = comp_cls(self.configs)
        comp_obj.preprocess()
        skyfiles = comp_obj.simulate()
        if self.products:
            self.products.add_component(compID, skyfiles)
        comp_obj.postprocess()

        t1_stop = time.perf_counter()
        t2_stop = time.process_time()
        logger.info("--------------------------------------------------")
        logger.info("Elapsed time: %.1f [min]" % ((t1_stop-t1_start)/60))
        logger.info("CPU process time: %.1f [min]" % ((t2_stop-t2_start)/60))
        logger.info("--------------------------------------------------")
test_regex.py 文件源码 项目:zmirror 作者: aploium 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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)
frozen.py 文件源码 项目:kripodb 作者: 3D-e-Chem 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def _ingest_pairs(self, pairs, oid2nid, frame_size, limit, single_sided):
        oid2nid_v = np.vectorize(oid2nid.get)
        # whole pairs set does not fit in memory, so split it in frames with `frame_size` number of pairs.
        for start in range(0, limit, frame_size):
            stop = frame_size + start
            t1 = process_time()
            six.print_('Fetching pairs {0}:{1} of {2} ... '.format(start, stop, limit), end='', flush=True)
            raw_frame = pairs.read(start=start, stop=stop)
            t2 = process_time()
            six.print_('{0}s, Parsing ... '.format(int(t2 - t1)), flush=True)
            frame = self._translate_frame(raw_frame, oid2nid_v, single_sided)
            t3 = process_time()
            six.print_('Writing ... '.format(int(t3 - t2)), flush=True)
            # alternate direction, to make use of cached chunks of prev frame
            self._ingest_pairs_frame(frame)
            del frame
            t4 = process_time()
            six.print_('{0}s, Done with {1}:{2} in {3}s'.format(int(t4 - t3), start, stop, int(t4 - t1)), flush=True)
console.py 文件源码 项目:fg21sim 作者: liweitianux 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def _task_test(self, **kwargs):
        """
        Test task ...
        """
        import time
        t1_start = time.perf_counter()
        t2_start = time.process_time()
        logger.info("Console TEST task: START ...")
        for i in range(kwargs["time"]):
            logger.info("Console TEST task: slept {0} seconds ...".format(i))
            time.sleep(1)
        logger.info("Console TEST task: DONE!")
        t1_stop = time.perf_counter()
        t2_stop = time.process_time()
        logger.info("Elapsed time: {0:.3f} (s)".format(t1_stop - t1_start))
        logger.info("CPU process time: {0:.3f} (s)".format(t2_stop - t2_start))
        return (True, None)
test_time.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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')
test_time.py 文件源码 项目:ouroboros 作者: pybee 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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')
test_time.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
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')
models_siamese.py 文件源码 项目:gcn_metric_learning 作者: sk1712 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def evaluate(self, data, labels, site, sess=None):
        """
        Runs one evaluation against the full epoch of data.
        Return the precision and the number of correct predictions.
        Batch evaluation saves memory and enables this to run on smaller GPUs.

        sess: the session in which the model has been trained.
        op: the Tensor that returns the number of correct predictions.
        data: size N x M
            N: number of signals (samples)
            M: number of vertices (features)
        labels: size N
            N: number of signals (samples)
        """
        t_process, t_wall = time.process_time(), time.time()
        scores, loss = self.predict(data, labels, site, sess)

        fpr, tpr, _ = roc_curve(labels, scores)
        roc_auc = auc(fpr, tpr)

        string = 'samples: {:d}, AUC : {:.2f}, loss: {:.4e}'.format(len(labels), roc_auc, loss)

        if sess is None:
            string += '\ntime: {:.0f}s (wall {:.0f}s)'.format(time.process_time() - t_process, time.time() - t_wall)
        return string, roc_auc, loss, scores
LogTimes.py 文件源码 项目:DenoiseAverage 作者: Pella86 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__(self):
        self.starttime = time.process_time()
        self.nowtime = time.process_time()
        self.lastcall = time.process_time()
LogTimes.py 文件源码 项目:DenoiseAverage 作者: Pella86 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __str__(self):
        self.nowtime = time.process_time()
        subtime =  self.nowtime - self.lastcall
        subtime = self.convert_in_ddhhss(subtime)
        s  = "Elapsed time for subprocess: {0}\n".format(subtime)

        totaltime = self.nowtime - self.starttime
        totaltime = self.convert_in_ddhhss(totaltime)
        s += "Time total elapsed: {0}".format(totaltime)

        self.lastcall = time.process_time()
        return s
common_items.py 文件源码 项目:Software-Architecture-with-Python 作者: PacktPublishing 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def timer():
    """ A simple timing function for routines """

    try:
        start = timer_func()
        yield
    except Exception as e:
        print(e)
        raise
    finally:
        end = timer_func()
        print ('Time spent=>',1000.0*(end - start),'ms.')
middleware.py 文件源码 项目:django-web-profiler 作者: MicroPyramid 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def process_request(self, request):
        self._start_time = time.time()
        self._start_rusage = resource.getrusage(resource.RUSAGE_SELF)
        self.t = time.process_time()
        response = super(DebugLoggingMiddleware, self).process_request(request)

        return response
fbx_utils.py 文件源码 项目:bpy_lambda 作者: bcongdon 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def level_down(self, message=""):
            if not self.ref_time:
                if message:
                    print(message)
                return
            ref_time = self.ref_time[self.level]
            print("\t" * self.level,
                  "\tDone (%f sec)\n" % ((time.process_time() - ref_time) if ref_time is not None else 0.0),
                  sep="")
            if message:
                print("\t" * self.level, message, sep="")
            del self.ref_time[self.level]
            self.level -= 1
fbx_utils.py 文件源码 项目:bpy_lambda 作者: bcongdon 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def step(self, message=""):
            ref_time = self.ref_time[self.level]
            curr_time = time.process_time()
            if ref_time is not None:
                print("\t" * self.level, "\tDone (%f sec)\n" % (curr_time - ref_time), sep="")
            self.ref_time[self.level] = curr_time
            print("\t" * self.level, message, sep="")
JPTimer.py 文件源码 项目:challenge-201608-refactor 作者: cohpy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __enter__(self):
        """
        Start timing something.

        Note - the with statement will invoke this automatically.
        :return: an instance of this class
        """
        self.start = time.process_time()
        return self
JPTimer.py 文件源码 项目:challenge-201608-refactor 作者: cohpy 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __exit__(self, *args):
        """
        Stop timing something and calculate the difference.

        Note - the with statement will invoke this automatically.
        :param args:
        :return:
        """
        self.end = time.process_time()
        self.interval = self.end - self.start
simulation.py 文件源码 项目:SimPype 作者: Mallets 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def run(self, *args, **kwargs):
        """ Run the simulation environment using SimPy environment. """
        self.log.init()
        sptime = time.process_time()
        self.env.run(*args, **kwargs)
        eptime = time.process_time()
        # Save some simulation parameters
        self.log.write("Simulation Seed: "+ str(self.seed))
        self.log.write("Simulation Time: " + "%.9f" % self.env.now)
        self.log.write("Execution Time: " + "%.9f" % (eptime - sptime))
dhmc_sampler.py 文件源码 项目:discontinuous-hmc 作者: aki-nishimura 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def run_sampler(self, theta0, dt_range, nstep_range, n_burnin, n_sample, seed=None, n_update=10):
        """Run DHMC and return samples and some additional info."""

        np.random.seed(seed)

        # Run HMC.
        theta = theta0
        n_per_update = math.ceil((n_burnin + n_sample) / n_update)
        pathlen_ave = 0
        samples = np.zeros((n_sample + n_burnin, len(theta)))
        logp_samples = np.zeros(n_sample + n_burnin)
        accept_prob = np.zeros(n_sample + n_burnin)

        tic = time.process_time()  # Start clock
        logp, grad, aux = self.f(theta)
        for i in range(n_sample + n_burnin):
            dt = np.random.uniform(dt_range[0], dt_range[1])
            nstep = np.random.randint(nstep_range[0], nstep_range[1] + 1)
            theta, logp, grad, aux, accept_prob[i], pathlen \
                = self.hmc(dt, nstep, theta, logp, grad, aux)
            pathlen_ave = i / (i + 1) * pathlen_ave + 1 / (i + 1) * pathlen
            samples[i, :] = theta
            logp_samples[i] = logp
            if (i + 1) % n_per_update == 0:
                print('{:d} iterations have been completed.'.format(i + 1))

        toc = time.process_time()
        time_elapsed = toc - tic
        print(('The average path length of each DHMC iteration was '
               '{:.2f}.'.format(pathlen_ave)))

        return samples, logp_samples, accept_prob, pathlen_ave, time_elapsed
mytools.py 文件源码 项目:chat 作者: Decalogue 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def time_me(info="used", format_string="ms"):
    """Performance analysis - time

    Decorator of time performance analysis.
    ????——????
    ????(wall clock time, elapsed time)???????????????????????
    ???????????CPU???????????????C++/Windows?????<time.h>???
    ??????????????????
    1.time.clock()??????????????CPU????????????????time.time()????
    time.clock()?????????????UNIX?????????"????"?????????????????
    ??WINDOWS????????????????????????????????????
    ???????????????????WIN32?QueryPerformanceCounter()???????????????
    2.time.perf_counter()?????????????????????????????
    ???????????????????????
    3.time.process_time()???????

    Args:
        info: Customize print info. ????????
        format_string: Specifies the timing unit. ?????????'s': ??'ms': ???
            Defaults to 's'.
    """
    def _time_me(func):
        @wraps(func)
        def _wrapper(*args, **kwargs):
            start = time.clock()
            # start = time.perf_counter()
            # start = time.process_time()
            result = func(*args, **kwargs)
            end = time.clock()
            if format_string == "s":
                print("%s %s %s"%(func.__name__, info, end - start), "s")
            elif format_string == "ms":
                print("%s %s %s" % (func.__name__, info, 1000*(end - start)), "ms")
            return result
        return _wrapper
    return _time_me
bench_skan.py 文件源码 项目:skan 作者: jni 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def timer():
    time = []
    t0 = process_time()
    yield time
    t1 = process_time()
    time.append(t1 - t0)
fcn_predict.py 文件源码 项目:fully-convolutional-network-semantic-segmentation 作者: alecng94 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def predict(testImgPath, imgDir, clipSize, net):

    # get file name
    pathArr = testImgPath.split('/')
    tmpFileName = pathArr[len(pathArr) - 1]
    filename = os.path.splitext(tmpFileName)[0]

    # preprocess image
    processedImg = preprocessImg(testImgPath, clipSize)

    # reshape image to be put into data layer
    # shape for input (data blob is N x C x H x W)
    net.blobs['data'].reshape(1, *processedImg.shape)
    print('Predicting...')
    net.blobs['data'].data[...] = processedImg

    # run net and take argmax for prediction
    t = time.process_time()
    net.forward()
    elapsed_time = time.process_time() - t
    out = net.blobs['score'].data[0].argmax(axis=0)
    print("Prediction time: %.3f" % elapsed_time)

    print('Saving...')
    savePrediction(imgDir, out, filename, testImgPath)
    print('Done processing image ' + filename)

    return elapsed_time


# @SUMMARY  : saves output of neural network into four different formats describe above
# @PARAM    : (imgDir) image target directory
# @PARAM    : (out) output of neural network
# @PARAM    : (filename) to save as
# @PARAM    : (testImgPath) for segmentation
Fusion360DebugUtilities.py 文件源码 项目:Fusion360AddinSkeleton 作者: tapnair 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def perf_log(log, function_reference, command, identifier=''):
    log.append((function_reference, command, identifier, time.process_time()))
test_time.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def test_process_time(self):
        # process_time() should not include time spend during a sleep
        start = time.process_time()
        time.sleep(0.100)
        stop = time.process_time()
        # use 20 ms because process_time() has usually a resolution of 15 ms
        # on Windows
        self.assertLess(stop - start, 0.020)

        info = time.get_clock_info('process_time')
        self.assertTrue(info.monotonic)
        self.assertFalse(info.adjustable)
decorators.py 文件源码 项目:feeluown-core 作者: cosven 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def log_exectime(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        t = time.process_time()
        result = func(*args, **kwargs)
        elapsed_time = time.process_time() - t
        logger.info('function %s executed time: %f ms'
                    % (func.__name__, elapsed_time * 1000))
        return result
    return wrapper
fbx_utils.py 文件源码 项目:blender-addons 作者: scorpion81 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def level_down(self, message=""):
            if not self.ref_time:
                if message:
                    print(message)
                return
            ref_time = self.ref_time[self.level]
            print("\t" * self.level,
                  "\tDone (%f sec)\n" % ((time.process_time() - ref_time) if ref_time is not None else 0.0),
                  sep="")
            if message:
                print("\t" * self.level, message, sep="")
            del self.ref_time[self.level]
            self.level -= 1
fbx_utils.py 文件源码 项目:blender-addons 作者: scorpion81 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def step(self, message=""):
            ref_time = self.ref_time[self.level]
            curr_time = time.process_time()
            if ref_time is not None:
                print("\t" * self.level, "\tDone (%f sec)\n" % (curr_time - ref_time), sep="")
            self.ref_time[self.level] = curr_time
            print("\t" * self.level, message, sep="")
tf_manager.py 文件源码 项目:neuralmonkey 作者: ufal 项目源码 文件源码 阅读 57 收藏 0 点赞 0 评论 0
def execute(self,
                dataset: Dataset,
                execution_scripts,
                train=False,
                compute_losses=True,
                summaries=True,
                batch_size=None,
                log_progress: int = 0) -> List[ExecutionResult]:
        if batch_size is None:
            batch_size = len(dataset)
        batched_dataset = dataset.batch_dataset(batch_size)
        last_log_time = time.process_time()

        batch_results = [
            [] for _ in execution_scripts]  # type: List[List[ExecutionResult]]
        for batch_id, batch in enumerate(batched_dataset):
            if (time.process_time() - last_log_time > log_progress
                    and log_progress > 0):
                log("Processed {} examples.".format(batch_id * batch_size))
                last_log_time = time.process_time()
            executables = [s.get_executable(compute_losses=compute_losses,
                                            summaries=summaries,
                                            num_sessions=len(self.sessions))
                           for s in execution_scripts]

            while not all(ex.result is not None for ex in executables):
                self._run_executables(batch, executables, train)

            for script_list, executable in zip(batch_results, executables):
                script_list.append(executable.result)

        collected_results = []  # type: List[ExecutionResult]
        for result_list in batch_results:
            collected_results.append(reduce_execution_results(result_list))

        return collected_results
learning_utils.py 文件源码 项目:neuralmonkey 作者: ufal 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _is_logging_time(step: int, logging_period_batch: int,
                     last_log_time: float, logging_period_time: int):
    if logging_period_batch is not None:
        return step % logging_period_batch == logging_period_batch - 1
    return last_log_time + logging_period_time < time.process_time()
tf_manager.py 文件源码 项目:neuralmonkey 作者: ufal 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def execute(self,
                dataset: Dataset,
                execution_scripts,
                train=False,
                compute_losses=True,
                summaries=True,
                batch_size=None,
                log_progress: int = 0) -> List[ExecutionResult]:
        if batch_size is None:
            batch_size = len(dataset)
        batched_dataset = dataset.batch_dataset(batch_size)
        last_log_time = time.process_time()

        batch_results = [
            [] for _ in execution_scripts]  # type: List[List[ExecutionResult]]
        for batch_id, batch in enumerate(batched_dataset):
            if (time.process_time() - last_log_time > log_progress
                    and log_progress > 0):
                log("Processed {} examples.".format(batch_id * batch_size))
                last_log_time = time.process_time()
            executables = [s.get_executable(compute_losses=compute_losses,
                                            summaries=summaries,
                                            num_sessions=len(self.sessions))
                           for s in execution_scripts]

            while not all(ex.result is not None for ex in executables):
                self._run_executables(batch, executables, train)

            for script_list, executable in zip(batch_results, executables):
                script_list.append(executable.result)

        collected_results = []  # type: List[ExecutionResult]
        for result_list in batch_results:
            collected_results.append(reduce_execution_results(result_list))

        return collected_results
learning_utils.py 文件源码 项目:neuralmonkey 作者: ufal 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _is_logging_time(step: int, logging_period_batch: int,
                     last_log_time: float, logging_period_time: int):
    if logging_period_batch is not None:
        return step % logging_period_batch == logging_period_batch - 1
    return last_log_time + logging_period_time < time.process_time()


问题


面经


文章

微信
公众号

扫码关注公众号