Skip to content

Instantly share code, notes, and snippets.

@ufechner7
Created August 23, 2015 17:47
Show Gist options
  • Save ufechner7/39124402f17eee3f40a8 to your computer and use it in GitHub Desktop.
Save ufechner7/39124402f17eee3f40a8 to your computer and use it in GitHub Desktop.
Test script for the realtime performance of Julia
using Winston
const SIMUL_DUR = 10.0 # simulation time in seconds
const PeriodTime = 20e-3 # period time for the simulation in seconds
const workload = 20000 # workload in vector additions/ multiplications per simulation step
const vec_size = 3
const cpu_usage = zeros(round(Int, SIMUL_DUR / PeriodTime)) # data array to log the cpu usage
const vec = zeros(vec_size, workload) # preallocate data array of 3D vectors
function step(step)
# sleep until the next simulation interval starts
while abs(mod(time(), PeriodTime)) > 1e-3
sleep(0.001)
end
tic();
for i in 1:workload # do some work
vec[:,i] += ones(vec_size)
vec[:,i] *= 2.2
end
cpu_usage[step] = toq() / PeriodTime;
end
function main()
step(1) # precompile the function step
step(2) # start the garbage collector
for i in 1:round(Int, SIMUL_DUR / PeriodTime)
step(i)
if mod(i, 100) == 0
println("Steps: $i")
end
end
crest_factor = maximum(cpu_usage) / mean(cpu_usage)
min_time = minimum(cpu_usage) * PeriodTime
max_time = maximum(cpu_usage) * PeriodTime
jitter = (max_time - min_time) * 1000
println("Jitter [ms]: $jitter")
println("Crest factor: $crest_factor")
plot(cpu_usage)
end
@ufechner7
Copy link
Author

To run this test script type:
include("RealTime.jl")
main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment