GVKun编程网logo

在 ipython 笔记本中测量单元执行时间的简单方法

17

本文的目的是介绍在ipython笔记本中测量单元执行时间的简单方法的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于iphone–在iPad或手机上的代码中测量EXACT执

本文的目的是介绍在 ipython 笔记本中测量单元执行时间的简单方法的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于iphone – 在iPad或手机上的代码中测量EXACT执行时间的代码?、python – 使用Py.Test测量单元测试特定文件的覆盖范围、python – 创建可能案例的简单方法、python 获取网络时间和本地时间的简单示例的知识。

本文目录一览:

在 ipython 笔记本中测量单元执行时间的简单方法

在 ipython 笔记本中测量单元执行时间的简单方法

除了单元格的原始输出之外,我还想获得在单元格执行上花费的时间。

为此,我尝试了,%%timeit -r1 -n1但它没有公开单元格中定义的变量。

%%time适用于仅包含 1 条语句的单元格。

In[1]: %%time
       1
CPU times: user 4 碌s,sys: 0 ns,total: 4 碌s
Wall time: 5.96 碌s
Out[1]: 1

In[2]: %%time
       # Notice there is no out result in this case.
       x = 1
       x
CPU times: user 3 碌s,total: 3 碌s
Wall time: 5.96 碌s

最好的方法是什么?

更新

我在 Nbextension中使用
Execute Time 已经有一段时间了。太好了。

更新 2021-03

到目前为止,这是正确的答案。从本质上讲,%%time现在%%timeit两者都按预期工作。

iphone – 在iPad或手机上的代码中测量EXACT执行时间的代码?

iphone – 在iPad或手机上的代码中测量EXACT执行时间的代码?

使用mach_absolute_time和由以下金鹰解释的简单NSDate方法是否有区别?

这是一个很好的解释,使用mach方法…

How do I accurately time how long it takes to call a function on the iPhone?

Measure time between library call and callback

解决方法

loop
  {
   NSDate *start = [NSDate date];

  // a considerable amount of difficult processing here
  // a considerable amount of difficult processing here
  // a considerable amount of difficult processing here

   NSDate *methodFinish = [NSDate date];
   NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:start];

   NSLog(@"Execution Time: %f",executionTime);
  }

应该工作。

python – 使用Py.Test测量单元测试特定文件的覆盖范围

python – 使用Py.Test测量单元测试特定文件的覆盖范围

我正试图用Py.Test检索我的单元测试的覆盖范围.问题是我得到了关于其他我不关心的 python文件的覆盖信息.

这是我的文件结构的一个例子.在这种情况下,我想测试:car.py,wheel.py和steer.py

python2.7 / site-packages中/

> car.py
> wheel.py
> steer.py
> coverage.py(来自pypi.python.org)
> yaml(python yaml库,来自pypi.python.org)
> pytest-2.5.2-py2.7.egg(python py.test库)
>还有更多

python2.7 /站点包/测试/

> test_car.py
> conftest.py

现在我使用Py.Test来执行测试:

python -m pytest --cov python2.7/site-packages/ python2.7/site-packages/test/test_car.py

但这导致了网站包中所有python文件的覆盖范围(有点明显).

python -m pytest --cov python2.7/site-packages/car.py python2.7/site-packages/test/test_car.py

这只会导致car.py的覆盖范围,而不是我想要的所有文件.

我怎样才能使用Py.Test来测量特定文件的覆盖范围?

(我也尝试过:

python -m pytest --cov python2.7/site-packages/car.py,python2.7/site-packages/wheel.py python2.7/site-packages/test/test_car.py

但是Py.Test不知道如何解析和使用这个参数.
)

解决方法

我找到了解决方案.您可以提供多个–cov文件参数.

python -m pytest \
  --cov python2.7/site-packages/car.py \
  --cov python2.7/site-packages/wheel.py \
  --cov python2.7/site-packages/steer.py \
  python2.7/site-packages/test/test_car.py

python – 创建可能案例的简单方法

python – 创建可能案例的简单方法

我有数据列表,如

a = [1,2,3,4]
b = ["a","b","c","d","e"]
c = ["001","002","003"]

我想创建一个新的另一个列表,混合了所有可能的a,b,c这样的情况

d = ["1a001","1a002","1a003",...,"4e003"]

有没有任何模块或方法来生成d而没有写多个for循环?

解决方法

[''''.join(str(y) for y in x) for x in itertools.product(a,c)]

python 获取网络时间和本地时间的简单示例

python 获取网络时间和本地时间的简单示例

对python这个高级语言感兴趣的小伙伴,下面一起跟随小编 jb51.cc的小编两巴掌来看看吧!

python获取网络时间


# @param python获取网络时间和本地时间
# @author 小编 jb51.cc|512Pic.com 

获取网络时间
 def getBeijinTime():
     
    获取北京时间
     
     try:
         conn = httplib.httpconnection(www.beijing-time.org)
         conn.request(GET,/time.asp)
         response = conn.getresponse()
         print response.status,response.reason
         if response.status == 200:
             #解析响应的消息
             result = response.read()
             logging.debug(result)
             data = result.split(\r\n)
             year = data[1][len(nyear)+1 : len(data[1])-1]
             month = data[2][len(nmonth)+1 : len(data[2])-1]
             day = data[3][len(nday)+1 : len(data[3])-1]
             #wday = data[4][len(nwday)+1 : len(data[4])-1]
             hrs = data[5][len(nhrs)+1 : len(data[5])-1]
             minute = data[6][len(nmin)+1 : len(data[6])-1]
             sec = data[7][len(nsec)+1 : len(data[7])-1]
              
             beijinTimeStr = %s/%s/%s %s:%s:%s % (year,month,day,hrs,minute,sec)
             beijinTime = time.strptime(beijinTimeStr,%Y/%m/%d %X)
             return beijinTime 
     except:
         logging.exception(getBeijinTime except)
         return None

# End www.jb51.cc

python获取本地时间


# @param python获取网络时间和本地时间
# @author 小编 jb51.cc|512Pic.com 

同步本地系统时间
 def syncLocalTime():
     
     同步本地时间
     
     logging.info(current local time is: %d-%d-%d %d:%d:%d % time.localtime()[:6])
      
     beijinTime = getBeijinTime() 
     if beijinTime is None:
         logging.info(get beijinTime is None,will try again in 30 seconds...)
         timer = threading.Timer(30.0,syncLocalTime)
         timer.start();
     else:
         logging.info(get beijinTime is: %d-%d-%d %d:%d:%d % beijinTime[:6])
              
         tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec = beijinTime[:6]
         import os
         os.system(date %d-%d-%d % (tm_year,tm_mday))     #设置日期
         os.system(time %d:%d:%d.0 % (tm_hour,tm_sec))    #设置时间
         logging.info(syncLocalTime complete,current local time: %d-%d-%d %d:%d:%d \n % time.localtime()[:6])

# End www.jb51.cc

今天关于在 ipython 笔记本中测量单元执行时间的简单方法的讲解已经结束,谢谢您的阅读,如果想了解更多关于iphone – 在iPad或手机上的代码中测量EXACT执行时间的代码?、python – 使用Py.Test测量单元测试特定文件的覆盖范围、python – 创建可能案例的简单方法、python 获取网络时间和本地时间的简单示例的相关知识,请在本站搜索。

本文标签: