Ray 简单性能对比

import time
import ray
@ray.remote
def multi(x):
    return x*x

def single_thread(x):
    return x*x

start = time.time()
parallel_result = [multi.remote(i) for i in range(100)]
diff = time.time()-start

print(diff)


start = time.time()
for i in range(100):
    temp_result = single_thread(i)
diff = time.time()-start
print(diff)

2021-10-20    学习了一篇文档 收获很大   共勉    Ray 1.0 架构解读

2021-10-21  快排使用ray 作分布式运行

          读文档: Ray design patternhttps://docs.google.com/document/d/167rnnDFIVRhHhK4mznEIemOtj63IOhtIPvSYaPgI4Fg/edit#


import ray
MINI_SIZE=10
def Partition(collection):
    pivolt = collection.pop(0)
    less, greater = [], []
    for item in collection:
        if item < pivolt:
            less.append(item)
        else:
            greater.append(item)
    return less, pivolt, greater

def quick_sort(collection):
    if len(collection) <= MINI_SIZE and len(collection)>0:
        collection.sort()
        return collection

    if len(collection) > MINI_SIZE:
        less, pivolt, greater = Partition(collection)
        less = quick_sort(less)
        greater = quick_sort(greater)

        return less + [pivolt] + greater

    return []

def main_quick_sort():
    import numpy as np

    collection = list(np.random.randint(300, 500, 100))
    start_time = time.time()
    result = quick_sort(collection)
    diff = time.time()-start_time
    return diff


@ray.remote
def quick_sort_ray(collection):
    if len(collection) <= MINI_SIZE and len(collection)>0:
        collection.sort()
        return collection

    if len(collection) > MINI_SIZE:
        less, pivolt, greater = Partition(collection)
        less = quick_sort(less)
        greater = quick_sort(greater)

        return less + [pivolt] + greater

    return []

def main_quick_sort_ray():
    import numpy as np

    collection = list(np.random.randint(300, 500, 100))
    start_time = time.time()
    result = quick_sort_ray.remote(collection)
    diff = time.time()-start_time
    return diff





diff_single=main_quick_sort()
diff_ray = main_quick_sort_ray()
print(diff_single)
print(diff_ray)

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值