8-Performance+Measurement+and+Improvement+Techniques

1.衡量代码的性能
2.提高代码性能的细节
3.学习函数cv.getTickCount,cv.getTickFrequency

1、用OpenCV衡量性能

cv.getTickCount函数返回针对参考事件调用函数时的时钟周期数。 所以如果你在函数执行前后调用它,你会得到用于执行函数的时钟周期数。
cv.getTickFrequency函数返回时钟周期的频率或每秒钟的时钟周期数。

import cv2 as cv
import numpy as np
#计算代码的执行时间
e1 = cv.getTickCount()
# your code execution
e2 = cv.getTickCount()
time = (e2 - e1)/ cv.getTickFrequency()
img1 = cv.imread('./images/wolf.jpg')
e1 = cv.getTickCount()
for i in range(5,49,2):
    img1 = cv.medianBlur(img1,i)
e2 = cv.getTickCount()
t = (e2 - e1)/cv.getTickFrequency()
print( t )
# Result I got is 0.521107655 seconds
1.947188311738297

2、OpenCV中的默认优化

很多OpenCV功能都使用SSE2,AVX等对代码进行优化。编译时默认启用。可以使用cv.useOptimized()检查是否启用/禁用,使用cv.setUseOptimized()启用/禁用

cv.useOptimized()
False
%timeit res = cv.medianBlur(img1,49)
90.3 ms ± 426 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
cv.setUseOptimized(True)
cv.useOptimized()
True
%timeit res = cv.medianBlur(img1,49)
91 ms ± 100 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

3、在IPython中衡量性能

x = 5
%timeit y=x**2
305 ns ± 3.03 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
%timeit y=x*x
42.3 ns ± 0.272 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
z = np.array([5])
print(z)
[5]
%timeit y=z*z
392 ns ± 5.95 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
%timeit y=np.square(z)
451 ns ± 0.907 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

4、优化技术

1.尽可能避免在Python中使用循环,特别是双/三循环等。它们本质上很慢。
2.因为Numpy和OpenCV针对向量操作进行了优化,所以可以尽可能地向最大程度地矢量化算法/代码。
利用缓存一致性。
3.除非需要,否则不要复制阵列的副本。 尝试使用视图。 阵列复制是一项代价高昂的操作。
4.即使在完成所有这些操作之后,如果代码仍然很慢,或者使用大循环是不可避免的,请使用Cython等其他库来加快速度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
英文版,经典书籍。 A Practical Guide to KPIs for the UTRAN Environment Contents Preface ix Acknowledgements xi 1 Basics of Performance Measurement in UMTS Terrestrial Radio Access Network (UTRAN) 1 1.1 General Ideas of Performance Measurement 2 1.1.1 What is a KPI? 4 1.1.2 KPI Aggregation Levels and Correlations 6 1.1.3 Basic Approach to Capture and Filter Performance-Related Data in UTRAN 7 1.1.4 Performance Measurement Definitions of 3GPP 13 1.1.5 User Experience vs. 3GPP Performance Measurement Definitions 16 1.1.5.1 Problems with Registration and Call Setup 17 1.1.5.2 Dropped Calls 19 1.1.5.3 Poor Transmission Speed 20 1.1.5.4 Corrupted Data 25 1.1.6 Basics of PS Call Analysis in UTRAN 27 1.2 Basic Architectural Concept of Performance Measurement Equipment Based on Protocol Analysis 34 1.2.1 Protocol Decoding and Protocol Stacks 37 1.2.2 Diversity Combining and Filtering 39 1.2.3 State Transition Analysis 44 1.3 Aggregation Levels/Dimensions 47 1.3.1 SGSN Dimension 47 1.3.2 MSC Dimension 48 1.3.3 SRNC Dimension 48 1.3.4 DRNC Dimension 48 1.3.5 CRNC Dimension 48 1.3.6 Node B Dimension 49 1.3.7 Cell Dimension 49 1.3.8 Call/Connection Dimension 51 1.3.9 UE Dimensions 51 1.3.10 Radio Bearer/Radio Access Bearer Type Dimensions 52 1.4 Statistics Calculation and Presentation 54 1.4.1 Sampling Period 54 1.4.2 Bins 56 1.4.3 The 95th Percentile 57 1.4.4 Gauges and Distribution Functions 58 2 Selected UMTS Key Performance Parameters 61 2.1 Block Error Rate (BLER) Measurements 61 2.1.1 Uplink Block Error Rate (UL BLER) 62 2.1.1.1 Uplink Transport Channel BLER 62 2.1.1.2 UL BLER per Call 65 2.1.1.3 UL BLER per Call Type 65 2.1.2 Downlink Block Error Rate (DL BLER) 65 2.1.2.1 DL BLER per Call or Service 68 2.1.3 Correlation of BLER and Other Measurements 69 2.2 Radio-Related Measurements 71 2.2.1 Radio Link Quality Parameters and Flow Control in Lub Frame Protocol (FP) 71 2.2.2 NBAP Common Measurements 74 2.2.2.1 Transmitted Carrier Power 76 2.2.2.2 NBAP Common Measurement Enhancements in Release 5 77 2.2.2.3 Received Total Wideband Power 78 2.2.3 NBAP Dedicated Measurements 81 2.2.3.1 Signal-to-Interference Ratio (SIR) 82 2.2.3.2 Signal-to-Interference Ratio Error (SIR Error) 83 2.2.3.3 Uplink SIR Target 85 2.2.3.4 Transmitted Code Power 86 2.2.3.5 Round Trip Time (RTT) 87 2.2.4 RRC Measurements and UE Measurement Abilities 87 2.3 Throughput Measurements 100 2.3.1 RLC Throughput 101 2.3.2 Transport Channel Throughput 102 2.3.3 Packet Switched User Perceived Throughput 112 2.3.4 Application Throughput 114 2.4 Transport Channel Usage Ratio 115 2.5 Primary and Secondary Traffic 118 2.6 Active Set Size Distribution 122 2.7 Soft Handover Success and Failure Analysis 127 2.8 Inter-Frequency Hard Handover Success and Failure Rates 132 2.9 Core Network Hard Handover Success and Failure Rates 137 2.9.1 Intra-MSC and Inter-MSC Hard Handover (3G-3G) 138 2.9.2 3G-2G Inter-RAT Handover for CS and PS Services 143 2.9.2.1 CS 3G-2G Inter-RAT Handover 144 2.9.2.2 PS 3G-2G Inter-RAT Handover 146 2.10 State Transitions and Channel Type Switching 147 2.11 Call Establish Success and Failure Rates 151 2.11.1 RRC Connection Establishment 152 2.11.2 Radio Bearer and Radio Access Bearer Establishment and Release 155 2.12 Call Drop Rates 160 2.13 NBAP Radio Link Failure Analysis and RRC Re-Establishment Success Rate 165 2.14 Cell Matrices 171 vi Contents 2.15 Miscellaneous Protocol Procedures and Events that Indicate Abnormal Behaviour of Protocol Entities on Different Layers 174 2.15.1 Miscellaneous RRC Failure Indications and Ratio KPIs 175 2.15.1.1 RRC UTRAN Mobility Information Failure 175 2.15.1.2 RRC Measurement Control Failure 175 2.15.1.3 RRC Status 175 2.15.1.4 RRC Security Mode Failure 176 2.15.1.5 RRC Transport Format Combination Control Failure 176 2.15.1.6 RRC Paging Response 176 2.15.2 SCCP Failure Analysis 177 2.15.2.1 Connection Refused (CREF) 177 2.15.2.2 Inactivity Check Failure 178 2.15.3 RANAP Failure Analysis 178 2.15.3.1 RANAP Reset Resource 178 2.15.3.2 RANAP Reset 178 2.15.3.3 RANAP Overload 178 2.15.4 NBAP Failure Analysis 178 2.15.5 RLC Acknowledge Mode Retransmission Rate 180 3 Call Establishment and Handover Procedures of PS Calls using HSDPA 181 3.1 HSDPA Cell Set Up 181 3.2 HSDPA Basic Call 182 3.2.1 Call Set Up and Measurement Initialisations 182 3.2.2 Call Release 187 3.3 Mobility Management and Handover Procedures in HSDPA 188 3.3.1 Serving HS-DSCH Cell Change without Change of Active Set 189 3.3.2 Inter-Node B Serving HS-DSCH Cell Change 191 3.3.3 HSDPA Cell Change After Soft Handover 193 Glossary 197 References 205 Index 207

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值