<分区>
我从 Pyspark 网站获取了以下 UDF,因为我试图了解是否存在性能改进。我做了很大范围的数字,但两者花费的时间几乎相同,我做错了什么?
谢谢!
import pandas as pd
from pyspark.sql.functions import col, udf
from pyspark.sql.types import LongType
import time
start = time.time()
# Declare the function and create the UDF
def multiply_func(a, b):
return a * b
multiply = udf(multiply_func, returnType=LongType())
# The function for a pandas_udf should be able to execute with local Pandas data
x = pd.Series(list(range(1, 1000000)))
print(multiply_func(x, x))
# 0 1
# 1 4
# 2 9
# dtype: int64
end = time.time()
print(end-start)
这是 Pandas UDF
import pandas as pd
from pyspark.sql.functions import col, pandas_udf
from pyspark.sql.types import LongType
import time
start = time.time()
# Declare the function and create the UDF
def multiply_func(a, b):
return a * b
multiply = pandas_udf(multiply_func, returnType=LongType())
# The function for a pandas_udf should be able to execute with local Pandas data
x = pd.Series(list(range(1, 1000000)))
print(multiply_func(x, x))
# 0 1
# 1 4
# 2 9
# dtype: int64