# Julia in Colab

**URL:** <https://discourse.julialang.org/t/julia-in-colab/126600>\
**Category:** General Usage\
**Tags:** colab\
**Created:** [March 5, 2025, 10:55pm UTC](https://discourse.julialang.org/t/julia-in-colab/126600 "2025-03-05T22:55:11Z")\
**Posts on this page:** 1\
**Showing post:** 42

<div class="post-metadata">

**Author:** ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Post date:** [March 11, 2025, 12:05pm UTC](https://discourse.julialang.org/t/julia-in-colab/126600/42 "2025-03-11T12:05:15Z")

</div>

You are not synchronizing the kernels, hence I believe you measure only the kernel launch. You need to `CUDA.@sync` the CUDA call.

```julia
using Pkg
Pkg.add("CUDA")
Pkg.add("BenchmarkTools")
using Plots, CUDA, BenchmarkTools

pMax = 8
powerVector = 1:pMax
timeVectorCPU = Vector{Float16}(undef, pMax)
timeVectorGPU = Vector{Float16}(undef, pMax)

for p in powerVector
    n = 10^p
    xCPU, yCPU = (ones(n), ones(n))
    xGPU, yGPU = (cu(xCPU), cu(yCPU))

    timeVectorCPU[p] = @belapsed $xCPU + $yCPU
    timeVectorGPU[p] = @belapsed CUDA.@sync $xGPU + $yGPU
end

timeVectorCPU |> display
timeVectorGPU |> display

plot(
    10 .^ powerVector, 
    [timeVectorCPU timeVectorGPU], 
    label = ["CPU" "GPU"], 
    title = "CPU vs GPU",
    xscale = :log10,
    yscale = :log10,
    ylabel = "Elapsed time [s]",
    fmt = :png
)

```

 ![Screenshot_2025-03-11_13-04-18](https://global.discourse-cdn.com/julialang/original/3X/8/1/81e33b4a694fd25e5bff5f5edca7222c1d0447c8.png)

---

_[View the full topic](https://discourse.julialang.org/t/julia-in-colab/126600)._
