# 并行计算效率不高

using BenchmarkTools
println(“\ec”)

function evaluatefunctions2(N)
#x = linspace(-1500.0, 1500.0, N)
x = range(-1500.0, stop=1500.0, length=N)
M = 10000
y = sin.(x)
x = asin.(y)
y = cos.(x)
x = acos.(y)
y = tan.(x)
x = atan.(y)
end
end

function evaluatefunctions1(N)
#x = linspace(-1500.0, 1500.0, N)
x = range(-1500.0, stop=1500.0, length=N)
M = 10000
for i in 1:M
y = sin.(x)
x = asin.(y)
y = cos.(x)
x = acos.(y)
y = tan.(x)
x = atan.(y)
end
end

using Distributed

function evaluatefunctions3(N)
#x = linspace(-1500.0, 1500.0, N)
x = range(-1500.0, stop=1500.0, length=N)
M = 10000
@sync @distributed for i in 1:M
y = sin.(x)
x = asin.(y)
y = cos.(x)
x = acos.(y)
y = tan.(x)
x = atan.(y)
end
end

println(“单线程单进程”)
@btime evaluatefunctions1(2000)
println(“12线程1进程”)
@btime evaluatefunctions2(2000)
println(“1线程12进程”)
println(“Number of process: \$(length(procs()))”)
@btime evaluatefunctions3(2000)

998.843 ms (60000 allocations: 922.85 MiB)
12线程1进程
210.809 ms (180079 allocations: 924.69 MiB)
1线程12进程
Number of process: 13
193.318 ms (1702 allocations: 62.84 KiB)

sim = Vector{Any}(undef,num)

pg = Progress(num; showspeed=true)