|
| 1 | +using SimJulia, Distributions, BenchmarkTools |
| 2 | + |
| 3 | +@stateful function exp_source(sim::Simulation, lambd::Float64, server::Resource, mu::Float64) |
| 4 | + while true |
| 5 | + dt = rand(Exponential(1/lambd)) |
| 6 | + @yield return Timeout(sim, dt) |
| 7 | + @Coroutine customer2(sim, server, mu) |
| 8 | + end |
| 9 | +end |
| 10 | + |
| 11 | +@stateful function customer(sim::Simulation, server::Resource, mu::Float64) |
| 12 | + @yield return Request(server) |
| 13 | + dt = rand(Exponential(1/mu)) |
| 14 | + @yield return Timeout(sim, dt) |
| 15 | + @yield return Release(server) |
| 16 | +end |
| 17 | + |
| 18 | +@stateful function customer2(sim::Simulation, server::Resource, mu::Float64) |
| 19 | + @Request server req begin |
| 20 | + dt = rand(Exponential(1/mu)) |
| 21 | + @yield return Timeout(sim, dt) |
| 22 | + end |
| 23 | +end |
| 24 | + |
| 25 | +function test_mm1(n::Float64) |
| 26 | + sim = Simulation() |
| 27 | + server = Resource(sim, 1) |
| 28 | + @Coroutine exp_source(sim, 1.0, server, 1.1) |
| 29 | + run(sim, n) |
| 30 | +end |
| 31 | + |
| 32 | +BenchmarkTools.DEFAULT_PARAMETERS.samples = 100 |
| 33 | +println(mean(@benchmark test_mm1(100.0))) |
0 commit comments