python 在python中使用此函数计算管道的各个部分

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 在python中使用此函数计算管道的各个部分相关的知识,希望对你有一定的参考价值。

from __future__ import print_function
from time import time as ts


def time_pipeline(iterable, *steps):
	''' this times the steps in a pipeline. 
		give it an iterable to test against 
		followed by the steps of the pipeline
		seperated in individual functions.
	'''
	durations = []
	for i in range(len(steps)):
		i += 1
		current_tasks = steps[:i]
		print('testing',current_tasks)
		duration = 0.0
		# run this test 1000 times 
		for t in range(100000):
			# build the generator
			test_generator = iter(iterable)
			for task in current_tasks:
				test_generator = task(test_generator)
			# time its execution
			start = ts()
			for i in test_generator:
				pass
			duration += ts() - start 
		durations.append(duration)
		if len(durations) == 1:
			print(durations[0],durations[0])
		else:
			print(durations[-1]-durations[-2],durations[-1])

l = list(range(50))

f1=lambda iterable:(i*2 for i in iterable)
f2=lambda iterable:(i*3 for i in iterable)
f3=lambda iterable:(i*4 for i in iterable)

time_pipeline(l, f1, f2, f3)

以上是关于python 在python中使用此函数计算管道的各个部分的主要内容,如果未能解决你的问题,请参考以下文章

Spark 管道中的 UDF

如何在 python call() 函数中使用“管道”? [复制]

使用 Python 脚本的 ADF 管道中的 Azure 函数

在 PySpark 中涉及带有管道的子进程的映射步骤失败

如何将 Python Lambda 函数集成到 AWS Amplify 的管道中

管道到头部导致从 python 调用的 shell 脚本中的管道损坏