• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python time.time函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: time

 def time(self, name):
     rt = RunTimer()
     before = time.time()
     yield rt  # Can call .set_result()
     after = time.time()
     elapsed = after - before
     self.log(name, "in {0:.2f} secs".format(elapsed), rt.result)
开发者ID:pthatcher,项目名称:psync,代码行数:7,代码来源:psync_simple.py


示例2: train

    def train(self, x, y, param_names, **kwargs):
        start = time.time()
        scaled_x = self._set_and_preprocess(x=x, param_names=param_names)

        # Check that each input is between 0 and 1
        self._check_scaling(scaled_x=scaled_x)

        if self._debug:
            print "Shape of training data: ", scaled_x.shape
            print "Param names: ", self._used_param_names
            print "First training sample\n", scaled_x[0]
            print "Encode: ", self._encode

        # Do a random search
        max_features, learning_rate, max_depth, min_samples_leaf, n_estimators = self._random_search(random_iter=100,
                                                                                                     x=scaled_x, y=y)
        # Now train model
        gb = GradientBoostingRegressor(loss='ls',
                                       learning_rate=learning_rate,
                                       n_estimators=n_estimators,
                                       subsample=1.0,
                                       min_samples_split=2,
                                       min_samples_leaf=min_samples_leaf,
                                       max_depth=max_depth,
                                       init=None,
                                       random_state=self._rng,
                                       max_features=max_features,
                                       alpha=0.9,
                                       verbose=0)
        gb.fit(scaled_x, y)
        self._model = gb

        duration = time.time() - start
        self._training_finished = True
        return duration
开发者ID:KEggensperger,项目名称:SurrogateBenchmarks,代码行数:35,代码来源:GradientBoosting.py


示例3: perform

  def perform(self, node, inputs, output_storage):
    start_time = time.time()
    log_posteriors, seq_lengths = inputs

    if numpy.isnan(log_posteriors).any():
      print >> log.v1, 'SprintErrorSigOp: log_posteriors contain NaN!'
    if numpy.isinf(log_posteriors).any():
      print >> log.v1, 'SprintErrorSigOp: log_posteriors contain Inf!'
      #numpy.set_printoptions(threshold=numpy.nan)
      print >> log.v1, 'SprintErrorSigOp: log_posteriors:', log_posteriors

    if self.sprint_instance_pool is None:
      print >> log.v3, "SprintErrorSigOp: Starting Sprint %r" % self.sprint_opts
      self.sprint_instance_pool = SprintInstancePool.get_global_instance(sprint_opts=self.sprint_opts)

    loss, errsig = self.sprint_instance_pool.get_batch_loss_and_error_signal(log_posteriors, seq_lengths)
    #print >> log.v4, 'loss:', loss, 'errsig:', errsig
    output_storage[0][0] = loss
    output_storage[1][0] = errsig

    print >> log.v5, 'SprintErrorSigOp: avg frame loss for segments:', loss.sum() / seq_lengths.sum()
    end_time = time.time()
    if self.debug_perform_time is None:
      from Config import get_global_config
      config = get_global_config()
      self.debug_perform_time = config.bool("debug_SprintErrorSigOp_perform_time", False)
    if self.debug_perform_time:
      print >>log.v1, "SprintErrorSigOp perform time:", end_time - start_time
      from Device import deviceInstance
      assert deviceInstance.is_device_proc()
      forward_time = start_time - deviceInstance.compute_start_time
      print >> log.v1, "SprintErrorSigOp forward time:", forward_time
开发者ID:atuxhe,项目名称:returnn,代码行数:32,代码来源:SprintErrorSignals.py


示例4: run

def run(clients, servers, startup=10):
	port = 10000
	server_procs = []
	for server in servers:
		print "starting", server
		proc = subprocess.Popen([sys.executable, server, str(port)], stdout=subprocess.PIPE)
		_PROCS.append(proc)
		server_procs.append(proc)
		proc.port = port
		proc.server_name = server
		start = time.time()
		while time.time() - start < startup:
			try:
				socket.create_connection( ('localhost', port))
				break
			except socket.error:
				pass
		else:  # didn't break
			raise EnvironmentError(
				"server {0} on port {1} didn't come ready within {2}s".format(
					server, port, startup))
		port += 1

	for serv in server_procs:
		print "SERVER", serv.server_name
		for client in clients:
			print "    CLIENT", client.__name__, client(serv.port)

		serv.kill()
开发者ID:doublereedkurt,项目名称:uhttp,代码行数:29,代码来源:run.py


示例5: add_engines

def add_engines(n=1, profile='iptest', total=False):
    """add a number of engines to a given profile.
    
    If total is True, then already running engines are counted, and only
    the additional engines necessary (if any) are started.
    """
    rc = Client(profile=profile)
    base = len(rc)
    
    if total:
        n = max(n - base, 0)
    
    eps = []
    for i in range(n):
        ep = TestProcessLauncher()
        ep.cmd_and_args = ipengine_cmd_argv + [
            '--profile=%s' % profile,
            '--InteractiveShell.colors=nocolor'
            ]
        ep.start()
        launchers.append(ep)
        eps.append(ep)
    tic = time.time()
    while len(rc) < base+n:
        if any([ ep.poll() is not None for ep in eps ]):
            raise RuntimeError("A test engine failed to start.")
        elif time.time()-tic > 15:
            raise RuntimeError("Timeout waiting for engines to connect.")
        time.sleep(.1)
    rc.close()
    return eps
开发者ID:marcjaxa,项目名称:EMAworkbench,代码行数:31,代码来源:test_ema_ipyparallel.py


示例6: readData

def readData():
    global rdObj
    rdObj.hostTemp = get_temperature()
    for i in range(60):
        timebegin = time.time()
        get_per_sec_info()
        time.sleep(1-(time.time()-timebegin))
开发者ID:abhinavk,项目名称:Virtproj,代码行数:7,代码来源:bgservice.py


示例7: find_proxy

def find_proxy( url, timeout, testing_url):

	try:
		response = urllib.urlopen( url )
	except:
		if Debug: print "Request to get proxy failed."
		return (False, False)

	result=response.getcode()

	content = response.read()

	data = json.loads( content )

	if Debug: print data['curl']

	start_time = time.time()

	try:
		response = urllib.urlopen(testing_url, proxies={'http':data['curl']})
	except:
		if Debug: print "Proxy test request failed."
		return (False, False)

	result=response.getcode()
	request_time = time.time() - start_time

	if result == 200: 
		if Debug: print "\n\nGot test url with %d in %f seconds" % (result, request_time)
		return (data['curl'], request_time)


	else:
		if Debug: print "Failed with %d" % result
		return (False, False)
开发者ID:Bschuster3434,项目名称:viral-launch-proxy-service,代码行数:35,代码来源:unknown.py


示例8: wait_for_completion

    def wait_for_completion(self):
        if self.is_old:
            self.old.wait_for_completion()
            return

        end = time.time() + self.timeout

        while db.guest_get_status(self.task_id) == "running":
            log.debug("%s: analysis still processing", self.vmid)

            time.sleep(1)

            # If the analysis hits the critical timeout, just return straight
            # away and try to recover the analysis results from the guest.
            if time.time() > end:
                raise CuckooGuestError(
                    "The analysis hit the critical timeout, terminating.")

            try:
                status = self.get("/status", timeout=5).json()
            except Exception as e:
                log.info("Virtual Machine /status failed (%r)", e)
                # this might fail due to timeouts or just temporary network issues
                # thus we don't want to abort the analysis just yet and wait for things to
                # recover
                continue

            if status["status"] == "complete":
                log.info("%s: analysis completed successfully", self.vmid)
                return
            elif status["status"] == "exception":
                log.info("%s: analysis caught an exception\n%s", self.vmid,
                         status["description"])
                return
开发者ID:certego,项目名称:cuckoo,代码行数:34,代码来源:guest.py


示例9: simple_find_in_context

    def simple_find_in_context(self, ref, context):
        """
        Like simple_find, but limits the search to a specific context.  Useful
        for when you want to (e.g.) make sure you only look in the webview.

        :param ref: an identifier for an element; id, class name, partial link text, etc.
        :param context: the context in which we're looking; typically WEBVIEW or NATIVE_APP
        :rtype: WebElement
        """
        # speed up the implicit wait, because with default time, this takes way
        # too long because of all the possible permutations
        self.implicitly_wait(HackedWebDriver.QuickImplicitWait_sec)

        # wrap this all in a try so we can restore the default implicit wait if
        # and when this block exits
        try:
            timeout = time.time() + self.MaxSmartSearchTime_sec
            while time.time() < timeout:
                element = self._simple_find_core(ref, context)
                if element:
                    return element
                log.debug(u'exhausted all search methods, looping until we timeout here')
        finally:
            # restore the default implicit wait
            self.implicitly_wait(HackedWebDriver.ImplicitWait_sec)

        assert False, u'couldnt find {}!'.format(ref)
开发者ID:PhoenixWright,项目名称:MobileBDDCore,代码行数:27,代码来源:webdriver.py


示例10: update_follower2leveldb

def update_follower2leveldb():
    # 从leveldb更新leveldb的用户粉丝数数据
    # test 0.15 seconds per 10000 users, total 22670000 users, 0.09 h
    users = xapian_search_user.iter_all_docs(fields=['user', 'followers_count'])
    
    count = 0
    ts = te = time.time()
    for k, v in user_followers_count_leveldb.RangeIter():
        uid = int(k)
        follower = int(v)
        
        try:
            active, important, _follower, domain = daily_identify_aifd_bucket.Get(str(uid)).split('_')
        except KeyError:
            active = 0
            important = 0
            domain = 20

        daily_identify_aifd_bucket.Put(str(uid), str(active) + '_' + str(important) + '_' + \
                                       str(follower) + '_' + str(domain))

        if count % 10000 == 0:
            te = time.time()
            print count, '%s sec' % (te - ts), ' identify person follower', now_datestr
            ts = te
        count += 1
开发者ID:huxiaoqian,项目名称:project,代码行数:26,代码来源:identify.py


示例11: update_domain2leveldb

def update_domain2leveldb():
    # 从leveldb更新leveldb的用户领域所属数据
    # test 0.15 seconds per 10000 users, total 22670000 users, 0.09 h
    count = 0
    ts = te = time.time()
    for k, v in domain_leveldb.RangeIter():
        uid, datestr = k.split('_')
        domainid = DOMAIN_LIST.index(v)

        try:
            active, important, follower, _domain = daily_identify_aifd_bucket.Get(str(uid)).split('_')
        except KeyError:
            active = 0
            important = 0
            follower = 0
        
        domain = domainid
        daily_identify_aifd_bucket.Put(str(uid), str(active) + '_' + str(important) + '_' + \
                                       str(follower) + '_' + str(domain))

        if count % 10000 == 0:
            te = time.time()
            print count, '%s sec' % (te - ts), ' identify person domain', now_datestr
            ts = te
        count += 1
开发者ID:huxiaoqian,项目名称:project,代码行数:25,代码来源:identify.py


示例12: main

def main():
    # Process CLI arguments.
    try:
        execname, host, port, mode = sys.argv
    except ValueError:
        execname = sys.argv[0]
        print >>sys.stderr, '%s: incorrect number of arguments' % execname
        print >>sys.stderr, 'usage: %s hostname port [sit|const|wild]' % sys.argv[0]
        sys.exit(-1)

    bzrc = BZRC(host, int(port))
    cur_time = time.time()
    
    agent = PigeonAgent(bzrc, mode, cur_time)

    # Run the agent
    try:
        
        while True:
            cur_time = time.time()
            agent.behave(cur_time)
            
                    
                
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        agent.stop()
        bzrc.close()
开发者ID:Altair3,项目名称:Tanks,代码行数:28,代码来源:PigeonAgent.py


示例13: main

def main():
    print("Code to look at runtime for insertion sort vs. Python's list sort.")
    
    numDig = 5 #number of digits to output
    
    #large list with numElements elements
    numElements = 10000
    data = []
    for i in range(numElements):
        data.append(randint(1, numElements))
        
    print("\nSorting list with " + str(len(data)) + " elements.\n")
    
    start = time.time()
    insertionSort(data)
    end = time.time()
    print("Insertion sort -> " + str(round(end - start, numDig)) + " seconds.")

    #large list with numElements elements
    numElements = 10000
    data = []
    for i in range(numElements):
        data.append(randint(1, numElements))
        
    start = time.time()
    data.sort()
    end = time.time()
    print("Python's sort -> " + str(round(end - start, numDig)) + " seconds.")
开发者ID:jedwardblack,项目名称:PythonPrograms,代码行数:28,代码来源:sortTest.py


示例14: testFolder

def testFolder(inputfolder, outputfolder, decisionThreshold = cfg.decision_threshold, applyNMS=True):

    fileList = os.listdir(inputfolder)
    imagesList = filter(lambda element: '.jpg' in element, fileList)

    print 'Start processing '+inputfolder

    start = time()
    for filename in imagesList:

        imagepath = inputfolder + '/' + filename
        print 'Processing '+imagepath

        #Test the current image
        bboxes, scores = testImage(imagepath, decisionThreshold=decisionThreshold, applyNMS=applyNMS)

        #Store the result in a dictionary
        result = dict()
        result['imagepath'] = imagepath
        result['bboxes'] = bboxes
        result['scores'] = scores

        #Save the features to a file using pickle
        outputFile = open(outputfolder+'/'+filename+'_'+'-'.join(cfg.featuresToExtract)+'_'+cfg.model+'.results', "wb")
        pickle.dump(result, outputFile)
        outputFile.close()
    elapsed_time = time() - start
    print('Time elapsed using regular function:  ', elapsed_time)
开发者ID:axelBarroso,项目名称:m3,代码行数:28,代码来源:detector.py


示例15: attach_volume

 def attach_volume(self, local_dev_timeout=120):
     new_device_name = None
     if not self.volume:
         raise FailureWithCode('This import does not have a volume', INPUT_DATA_FAILURE)
     instance_id = self.instance_id
     devices_before = get_block_devices()
     device_name = self.next_device_name(devices_before)
     log.debug('Attaching volume {0} to {1} as {2}'.
                      format(self.volume.id, instance_id, device_name), self.task_id)
     self.ec2_conn.attach_volume_and_wait(self.volume.id,
                                          instance_id,
                                          device_name)
     elapsed = 0
     start = time.time()
     while elapsed < local_dev_timeout and not new_device_name:
         new_block_devices = get_block_devices()
         log.debug('Waiting for local dev for volume: "{0}", '
                          'elapsed:{1}'.format(self.volume.id, elapsed), self.task_id)
         diff_list = list(set(new_block_devices) - set(devices_before))
         if diff_list:
             for dev in diff_list:
                 # If this is virtio attempt to verify vol to dev mapping
                 # using serial number field info
                 if not os.path.basename(dev).startswith('vd'):
                     try:
                         self.verify_virtio_volume_block_device(
                             volume_id=self.volume.id,
                             blockdev=dev)
                     except ValueError, ex:
                         raise FailureWithCode(ex, ATTACH_VOLUME_FAILURE)
                 new_device_name = dev
                 break
         elapsed = time.time() - start
         if elapsed < local_dev_timeout:
             time.sleep(2)
开发者ID:feoff3,项目名称:eucalyptus-imaging-worker,代码行数:35,代码来源:imaging_task.py


示例16: wait

    def wait(self, status):
        """Waiting for status.
        @param status: status.
        @return: always True.
        """
        log.debug("%s: waiting for status 0x%.04x", self.id, status)

        end = time.time() + self.timeout
        self.server._set_timeout(self.timeout)

        while db.guest_get_status(self.task_id) == "starting":
            # Check if we've passed the timeout.
            if time.time() > end:
                raise CuckooGuestError("{0}: the guest initialization hit the "
                                       "critical timeout, analysis "
                                       "aborted.".format(self.id))

            try:
                # If the server returns the given status, break the loop
                # and return.
                if self.server.get_status() == status:
                    log.debug("%s: status ready", self.id)
                    break
            except:
                pass

            log.debug("%s: not ready yet", self.id)
            time.sleep(1)

        self.server._set_timeout(None)
        return True
开发者ID:certego,项目名称:cuckoo,代码行数:31,代码来源:guest.py


示例17: watch_server_pids

def watch_server_pids(server_pids, interval=1, **kwargs):
    """Monitor a collection of server pids yeilding back those pids that
    aren't responding to signals.

    :param server_pids: a dict, lists of pids [int,...] keyed on
                        Server objects
    """
    status = {}
    start = time.time()
    end = start + interval
    server_pids = dict(server_pids)  # make a copy
    while True:
        for server, pids in server_pids.items():
            for pid in pids:
                try:
                    # let pid stop if it wants to
                    os.waitpid(pid, os.WNOHANG)
                except OSError, e:
                    if e.errno not in (errno.ECHILD, errno.ESRCH):
                        raise  # else no such child/process
            # check running pids for server
            status[server] = server.get_running_pids(**kwargs)
            for pid in pids:
                # original pids no longer in running pids!
                if pid not in status[server]:
                    yield server, pid
            # update active pids list using running_pids
            server_pids[server] = status[server]
        if not [p for server, pids in status.items() for p in pids]:
            # no more running pids
            break
        if time.time() > end:
            break
        else:
            time.sleep(0.1)
开发者ID:Willtech,项目名称:swift,代码行数:35,代码来源:manager.py


示例18: __check_ssh_agent

def __check_ssh_agent():
  """Check that an ssh-agent is present and has at least one valid looking
  identity loaded into it."""

  # There's no way to do this w/ putty/pageant and that's OK because
  # they don't hang up on prompting for passwords
  if sys.platform == 'win32':
    return True
  
  app = wingapi.gApplication
  if not app.fSingletons.fFileAttribMgr[_kCheckSSHAgent]:
    return True
  
  cmd = 'ssh-add'
  handler = app.AsyncExecuteCommandLine(cmd, os.getcwd(), '-l')
  end = time.time() + 1.0
  while not handler.Iterate() and time.time() < end:
    time.sleep(0.01)
  stdout, stderr, err, status = handler.Terminate()
  if err is None:
    out = stdout + stderr
    if len(out) > 0 and not out.find('no identities') >= 0 and not out.find('not open') >= 0:
      return True
    
  return False
开发者ID:aorfi,项目名称:2015-2016-Backup,代码行数:25,代码来源:cvs.py


示例19: run_proc_rr

    def run_proc_rr(self, process_table, memory_pool, placement_algo): # handle process queue
        # stats
        self.switch_count = 0
        avg_burst_time = 0.0
        self.avg_wait_time = 0.0

        print "time 0ms: Simulator started for RR and %s"%placement_algo
        self.t0 = time.time()

        # at the very begining when no process has arrived
        process_queue = Queue();
        self.new_arrival_proc(process_table, process_queue, memory_pool, placement_algo)

        while len(process_table):
            self.proc_rr_loop(process_table, process_queue, memory_pool, placement_algo)
        print "time %sms: Simulator for RR and %s ended"%(int(1000*(time.time()-self.t0)) + self.t_pseudo_elapsed, placement_algo)
        # stat
        burst_num = 0
        for val in self.process_table.values():
            avg_burst_time += (val['burst_time']*val['num_burst'])
            burst_num += val['num_burst']
        self.avg_turnaround_time = (self.avg_wait_time + self.t_cs*self.switch_count + avg_burst_time + self.t_pseudo_elapsed)/burst_num
        avg_burst_time /= burst_num
        self.avg_wait_time /= burst_num
        print "Algorithm RR and %s"%placement_algo
        print "-- average CPU burst time: %.2f ms"%avg_burst_time
        print "-- average wait time: %.2f ms"%self.avg_wait_time
        print "-- average turnaround time: %.2f ms"%self.avg_turnaround_time
        print "-- total number of context switches: %s"%self.switch_count
开发者ID:hugochan,项目名称:OS,代码行数:29,代码来源:baseos.py


示例20: connect

 def connect(self, address):
     if isinstance(address, tuple) and len(address)==2:
         address = gethostbyname(address[0]), address[1]
     if self.timeout == 0.0:
         return self._sock.connect(address)
     sock = self._sock
     if self.timeout is None:
         while True:
             err = sock.getsockopt(SOL_SOCKET, SO_ERROR)
             if err:
                 raise error(err, strerror(err))
             result = sock.connect_ex(address)
             if not result or result == EISCONN:
                 break
             elif (result in (EWOULDBLOCK, EINPROGRESS, EALREADY)) or (result == EINVAL and is_windows):
                 wait_readwrite(sock.fileno())
             else:
                 raise error(result, strerror(result))
     else:
         end = time.time() + self.timeout
         while True:
             err = sock.getsockopt(SOL_SOCKET, SO_ERROR)
             if err:
                 raise error(err, strerror(err))
             result = sock.connect_ex(address)
             if not result or result == EISCONN:
                 break
             elif (result in (EWOULDBLOCK, EINPROGRESS, EALREADY)) or (result == EINVAL and is_windows):
                 timeleft = end - time.time()
                 if timeleft <= 0:
                     raise timeout('timed out')
                 wait_readwrite(sock.fileno(), timeout=timeleft)
             else:
                 raise error(result, strerror(result))
开发者ID:strogo,项目名称:pylibs,代码行数:34,代码来源:socket.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python time.timer函数代码示例发布时间:2022-05-27
下一篇:
Python time.ticks_ms函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap