Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

需要建立python与c++各数据转换的性能baseline,用于指导性能优化 #489

Closed
wangxicoding opened this issue Apr 26, 2020 · 2 comments
Assignees

Comments

@wangxicoding
Copy link
Contributor

python<-->python转换需测数据:

源数据格式 目标数据格式 转换方法 数据大小
numpy list list(src) 1MB..
numpy list src.tolist() .
ctypes list list(src) .
ctypes list src[:] .
list numpy np.array(list) .
list ctypes dst[:] = src[:] .
list ctypes cp(*src) .

c++ <--> python转换需测数据:

源数据格式 目标数据格式 转换方法 数据大小
list vector 1MB..
numpy vector .
ctypes vector .
vector list .
vector numpy .
vector ctypes .
@wangxicoding
Copy link
Contributor Author

import numpy as np
import ctypes

length = 16 * 3 * 224 * 224

src_np = np.array(np.random.randn(length), dtype="float32")
%timeit dst_list = list(src_np)
%timeit dst_list = src_np.tolist()

src_ctype = ctypes.c_float * length
src_cp = src_ctype()
%timeit dst_list = list(src_cp)
%timeit dst_list = src_cp[:]

src_list = [float(1.0 * i / length) for i in range(length)]
%timeit dst_np = np.array(src_list, dtype='float32')
%timeit src_cp[:] = src_list
%timeit -n 10 dst_cp = src_ctype(*src_list)

比如用ipython的%timeit的来获取性能
image

@MRXLT MRXLT self-assigned this Apr 26, 2020
@MRXLT
Copy link
Contributor

MRXLT commented Apr 29, 2020

10 loops

size 1024 * 1024

type float32

python to python

origin type target type cost ms function
np.array list 485.650 list(src)
np.array list 252.208 src.tolist()
ctype list 1651.359 list(src)
ctype list 394.009 src[:]
list np.array 310.021 np.array()
list ctype 412.384 src_cp[:]=src_list
list ctype 2467.857 cp(*src)

@paddle-bot paddle-bot bot closed this as completed Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants