当前位置: 首页>>代码示例>>Python>>正文


Python utils.timed函数代码示例

本文整理汇总了Python中utils.timed函数的典型用法代码示例。如果您正苦于以下问题:Python timed函数的具体用法?Python timed怎么用?Python timed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了timed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_guarded

    def run_guarded(self, context):
        period = context.period

        if config.log_level == "processes":
            print()

        try:
            for k, v in self.subprocesses:
                if config.log_level == "processes":
                    print("    *", end=' ')
                    if k is not None:
                        print(k, end=' ')
                    utils.timed(v.run_guarded, context)
                else:
                    v.run_guarded(context)
                    #            print "done."
                context.simulation.start_console(context)
        finally:
            if config.autodump is not None:
                self._autodump(context)

            if config.autodiff is not None:
                self._autodiff(period)

            if self.purge:
                self.entity.purge_locals()
开发者ID:antoinearnoud,项目名称:liam2,代码行数:26,代码来源:process.py

示例2: upload_box

def upload_box(mail, api, cmax=None):
  result, data = mail.search(None, "ALL")
  if result == 'OK':
    ids = data[0].split() # Ids is a space separated string.
    ids.reverse()
    if cmax is None:
      cmax = len(ids)
    else:
      cmax = min(cmax, len(ids))
    i = 0
    tfetch = 0
    tupload = 0
    print('0.0 %', end='')
    for id in ids[:cmax]:
      # Fetch raw message.
      (result, data), elapsed = timed(mail.fetch, id, "(RFC822)") # fetch the email body (RFC822) for the given ID.
      tfetch += elapsed
      # Encode.
      raw = data[0][1] # Raw mail, in bytes.
      data, cte = _decode(raw)
      # Upload into API.
      try:
        result, elapsed = timed(api.message_insert, 'media', data, cte)
        tupload += elapsed
      except ApiError as err:
        print('\nFailed to upload one message: {}\n'.format(err))
      # Progress.
      i = i+1
      percent = i * 100 / cmax
      print('\r\033[0K{0:.2f} %'.format(percent), end='')
    print('\r\033[0KDone.\n-- fetch time: {}\n-- upload time {}'.format(tfetch, tupload))
  else:
    print('Could not access the mail box: {}'.format(result))
开发者ID:DarkDare,项目名称:PEPS,代码行数:33,代码来源:import.py

示例3: simulate_period

        def simulate_period(period_idx, period, processes, entities,
                            init=False):
            print("\nperiod", period)
            if init:
                for entity in entities:
                    print("  * %s: %d individuals" % (entity.name,
                                                      len(entity.array)))
            else:
                print("- loading input data")
                for entity in entities:
                    print("  *", entity.name, "...", end=' ')
                    timed(entity.load_period_data, period)
                    print("    -> %d individuals" % len(entity.array))
            for entity in entities:
                entity.array_period = period
                entity.array['period'] = period

            if processes:
                # build context for this period:
                const_dict = {'__simulation__': self,
                              'period': period,
                              'nan': float('nan'),
                              '__globals__': globals_data}

                num_processes = len(processes)
                for p_num, process_def in enumerate(processes, start=1):
                    process, periodicity = process_def

                    print("- %d/%d" % (p_num, num_processes), process.name,
                          end=' ')
                    print("...", end=' ')
                    if period_idx % periodicity == 0:
                        elapsed, _ = gettime(process.run_guarded, self,
                                             const_dict)
                    else:
                        elapsed = 0
                        print("skipped (periodicity)")

                    process_time[process.name] += elapsed
                    if config.show_timings:
                        print("done (%s elapsed)." % time2str(elapsed))
                    else:
                        print("done.")
                    self.start_console(process.entity, period,
                                       globals_data)

            print("- storing period data")
            for entity in entities:
                print("  *", entity.name, "...", end=' ')
                timed(entity.store_period_data, period)
                print("    -> %d individuals" % len(entity.array))
#            print " - compressing period data"
#            for entity in entities:
#                print "  *", entity.name, "...",
#                for level in range(1, 10, 2):
#                    print "   %d:" % level,
#                    timed(entity.compress_period_data, level)
            period_objects[period] = sum(len(entity.array)
                                         for entity in entities)
开发者ID:leeseungho90,项目名称:liam2,代码行数:59,代码来源:simulation.py

示例4: simulate_period

        def simulate_period(period_idx, period, processes, entities, init=False):
            print "\nperiod", period
            if init:
                for entity in entities:
                    print "  * %s: %d individuals" % (entity.name, len(entity.array))
            else:
                print "- loading input data"
                for entity in entities:
                    print "  *", entity.name, "...",
                    timed(entity.load_period_data, period)
                    print "    -> %d individuals" % len(entity.array)
            for entity in entities:
                entity.array_period = period
                entity.array["period"] = period

            if processes:
                # build context for this period:
                const_dict = {"period": period, "nan": float("nan"), "__globals__": globals_data}

                num_processes = len(processes)
                for p_num, process_def in enumerate(processes, start=1):
                    process, periodicity = process_def

                    print "- %d/%d" % (p_num, num_processes), process.name,
                    # TODO: provide a custom __str__ method for Process &
                    # Assignment instead
                    if hasattr(process, "predictor") and process.predictor and process.predictor != process.name:
                        print "(%s)" % process.predictor,
                    print "...",
                    if period_idx % periodicity == 0:
                        elapsed, _ = gettime(process.run_guarded, self, const_dict)
                    else:
                        elapsed = 0
                        print "skipped (periodicity)"

                    process_time[process.name] += elapsed
                    if config.show_timings:
                        print "done (%s elapsed)." % time2str(elapsed)
                    else:
                        print "done."
                    self.start_console(process.entity, period, globals_data)

            print "- storing period data"
            for entity in entities:
                print "  *", entity.name, "...",
                timed(entity.store_period_data, period)
                print "    -> %d individuals" % len(entity.array)
            #            print " - compressing period data"
            #            for entity in entities:
            #                print "  *", entity.name, "...",
            #                for level in range(1, 10, 2):
            #                    print "   %d:" % level,
            #                    timed(entity.compress_period_data, level)
            period_objects[period] = sum(len(entity.array) for entity in entities)
开发者ID:abozio,项目名称:Myliam2,代码行数:54,代码来源:simulation.py

示例5: run_guarded

 def run_guarded(self, simulation, const_dict):
     print
     for k, v in self.subprocesses:
         print "    *",
         if k is not None:
             print k,
         utils.timed(v.run_guarded, simulation, const_dict)
         #            print "done."
         simulation.start_console(v.entity, const_dict["period"], const_dict["__globals__"])
     # purge all local variables
     temp_vars = self.entity.temp_variables
     all_vars = self.entity.variables
     local_vars = set(temp_vars.keys()) - set(all_vars.keys())
     for var in local_vars:
         del temp_vars[var]
开发者ID:abozio,项目名称:Myliam2,代码行数:15,代码来源:process.py

示例6: aggregate

    def aggregate(self, report_id):
        logbook.info("Get customer usage aggregation for {}", report_id)
        customer = Customer.get_by_id(report_id.customer_id)
        if not customer:
            raise Exception("Customer %s not found" % report_id.customer_id)

        with timed("get_usage simple"):
            aggregated_usage = ServiceUsage.get_usage(customer, report_id.start, report_id.end)

        tariffs = {}
        services = set()
        for usage in aggregated_usage:
            service_id, tariff_id, cost, usage_volume = usage
            services.add(service_id)
            if not tariff_id:
                logbook.error("ServiceUsage {} is not completed. Tariff is not filled", usage)
                continue
            tariff = Tariff.get_by_id(tariff_id)
            tariff_report = tariffs.get(tariff_id)
            if tariff_report is None:
                tariff_report = self.tariff_report_type(tariff, customer)
                tariffs[tariff_id] = tariff_report

            tariff_report.add_usage(usage)

        total = Counter()
        for tariff_id, tariff in tariffs.items():
            total_tariff, currency = tariff.aggregate()
            total[currency] += total_tariff

        for t, value in total.items():
            total[t] = decimal_to_string(value)

        logbook.info("Aggregated {} for {}. Services: {}", total, customer, services)
        return self.prepare_result(list(tariffs.values()), total, customer, report_id.start, report_id.end)
开发者ID:deti,项目名称:boss,代码行数:35,代码来源:simple.py

示例7: run_guarded

    def run_guarded(self, simulation, const_dict):
        period = const_dict['period']

        print()
        for k, v in self.subprocesses:
            print("    *", end=' ')
            if k is not None:
                print(k, end=' ')
            utils.timed(v.run_guarded, simulation, const_dict)
#            print "done."
            simulation.start_console(v.entity, period,
                                     const_dict['__globals__'])
        if config.autodump is not None:
            self._autodump(period)

        if config.autodiff is not None:
            self._autodiff(period)

        if self.purge:
            self.entity.purge_locals()
开发者ID:leeseungho90,项目名称:liam2,代码行数:20,代码来源:process.py

示例8: run_guarded

    def run_guarded(self, simulation, const_dict):
        global max_vars
        
        periods = const_dict['periods']
        idx = const_dict['period_idx']
        period =  periods[idx]
        
        print()
        for k, v in self.subprocesses:
#             print("    *", end=' ')
            if k is not None:
                print(k, end=' ')
            utils.timed(v.run_guarded, simulation, const_dict)
#            print "done."
            simulation.start_console(v.entity, period,
                                     const_dict['__globals__'])
        if config.autodump is not None:
            self._autodump(period)

        if config.autodiff is not None:
            self._autodiff(period)

        # purge all local variables
        temp_vars = self.entity.temp_variables
        all_vars = self.entity.variables
        local_var_names = set(temp_vars.keys()) - set(all_vars.keys())
        num_locals = len(local_var_names)
        if config.debug and num_locals:
            local_vars = [v for k, v in temp_vars.iteritems()
                          if k in local_var_names and
                             isinstance(v, np.ndarray)]
            max_vars = max(max_vars, num_locals)
            temp_mem = sum(v.nbytes for v in local_vars)
            avgsize = sum(v.dtype.itemsize for v in local_vars) / num_locals
            print(("purging {} variables (max {}), will free {} of memory "
                  "(avg field size: {} b)".format(num_locals, max_vars,
                                                  utils.size2str(temp_mem),
                                                  avgsize)))

        for var in local_var_names:
            del temp_vars[var]
开发者ID:AnneDy,项目名称:Til-Liam,代码行数:41,代码来源:process.py

示例9: report_file_generate

def report_file_generate(self, report_id):
    from report import Report
    from memdb.report_cache import ReportCache, ReportTask

    report_cache = ReportCache()

    aggregated = report_cache.get_report_aggregated(report_id)
    if not aggregated:
        aggregated = get_aggregation(report_id)
        aggregated = ReportCache.unpack_aggregated(ReportCache.pack_aggregated(aggregated))
    report_generator = Report.get_report(report_id.report_type)
    with timed("rendering for %s" % report_id):
        data = report_generator.render(aggregated, report_id)
    report_cache.set_report(report_id, data, report_generator.report_cache_time)
    ReportTask().remove(report_id)
开发者ID:deti,项目名称:boss,代码行数:15,代码来源:customer.py

示例10: user_tiles

def user_tiles(adapter, count=5000):

    query = timed(adapter.query_tile_time_percent)

    time_sum = 0
    with open('./tiles.txt') as f:
        queries = (tuple(int(x) for x in line.split('/')[1:5]) for line in f)
        for zoom, resolution, x, y in itertools.islice(queries, count):
        
            time_v, count_v = query(x, y, zoom, resolution, 0.0, 1.0)
            time_sum += time_v.microseconds

            time.sleep(DELAY)
        
        average = time_sum / count / 1.e6
        print 'User queries: average time {}'.format(average)
开发者ID:seanastephens,项目名称:idc-benchmark,代码行数:16,代码来源:full-benchmark.py

示例11: filter_and_group

    def filter_and_group(usage):
        usage_by_resource = defaultdict(list)
        with timed("filter and group by resource"):
            trust_sources = set(conf.fitter.trust_sources)
            for u in usage:
                # the user can make their own samples, including those
                # that would collide with what we care about for
                # billing.
                # if we have a list of trust sources configured, then
                # discard everything not matching.
                if trust_sources and u.source not in trust_sources:
                    logbook.warning('ignoring untrusted usage sample from source `{}`', u['source'])
                    continue

                resource_id = u.resource_id
                usage_by_resource[resource_id].append(u)
        return usage_by_resource
开发者ID:deti,项目名称:boss,代码行数:17,代码来源:collector.py

示例12: get_tenant_usage

    def get_tenant_usage(self, tenant_id, meter_name, start, end, limit=None):
        """ Queries ceilometer for all the entries in a given range,
           for a given meter, from this tenant."""

        query = [self.filter('timestamp', 'ge', start), self.filter('timestamp', 'lt', end)]

        if tenant_id:
            query.append(self.filter('project_id', 'eq', tenant_id))

        if meter_name:
            query.append(self.filter('meter', 'eq', meter_name))

        with timed('fetch global usage for meter %s' % meter_name):
            result = openstack.client_ceilometer.new_samples.list(q=query, limit=limit)
            log.debug("Get usage for tenant: {} and meter_name {} ({} - {}). Number records: {}",
                      tenant_id, meter_name, start, end, len(result))
            return result
开发者ID:deti,项目名称:boss,代码行数:17,代码来源:openstack_wrapper.py

示例13: region_time

def region_time(adapter, latlon_mag=160, latlon_step=160, time_steps=5, zoom=4):
    
    lat0s = lat1s = lon0s = lon1s = [float(x) / 180. for x in range(-latlon_mag, latlon_mag + latlon_step, latlon_step)]
    starts = ends = [float(x) / time_steps for x in range(time_steps)]
    
    query = timed(adapter.query_region_latlon_time_percent)
    
    count = 0
    time_sum = 0.
    for lat0, lat1, lon0, lon1, start, end in itertools.product(lat0s, lat1s, lon0s, lon1s, starts, ends):
        if lat0 >= lat1 or lon0 >= lon1 or start >= end: continue
                    
        time_v, count_v = query(lat0, lon0, lat1, lon1, zoom, start, end)
        count += 1
        time_sum += time_v.microseconds
    
        time.sleep(DELAY)

    print 'For regions, average time {}'.format(time_sum / count / 1.e6)
开发者ID:seanastephens,项目名称:idc-benchmark,代码行数:19,代码来源:full-benchmark.py

示例14: tile_time_resolution

def tile_time_resolution(adapter, time_steps=5, zoom=4, tile_samples=20, resolution=8):

    random.seed(1)
    all_coords = list(itertools.product(range(0, 2**zoom), range(0, 2**zoom)))
    coords = random.sample(all_coords, tile_samples)

    starts = ends = [float(x) / time_steps for x in range(time_steps)]

    query = timed(adapter.query_tile_time_percent)

    count = 0
    time_sum = 0
    for start, end, (x, y) in itertools.product(starts, ends, coords):
        if start >= end: continue
    
        time_v, count_v = query(x, y, zoom, resolution, start, end)
        count += 1
        time_sum += time_v.microseconds

        time.sleep(DELAY)
    
    average = time_sum / count / 1.e6
    print 'At resolution {} average time {}'.format(resolution, average)
开发者ID:seanastephens,项目名称:idc-benchmark,代码行数:23,代码来源:full-benchmark.py

示例15: sql_batch_insert

import utils

from contextlib import closing

from django.db import connection
from django.utils import timezone


def sql_batch_insert(n_records):
    sql = 'INSERT INTO app_testmodel (field_1, field_2, field_3) VALUES {}'.format(
        ', '.join(['(%s, %s, %s)'] * n_records),
    )
    params = []
    for i in xrange(0, n_records):
        params.extend([i, str(i), timezone.now()])

    with closing(connection.cursor()) as cursor:
        cursor.execute(sql, params)


if __name__ == '__main__':
    utils.timed(sql_batch_insert)
开发者ID:stefano,项目名称:bulk_insert_experiment,代码行数:22,代码来源:sql_batch_insert.py


注:本文中的utils.timed函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。