Lesson 36 of 55
9 mins readPython Built-in Diagnostic Macros (@show, @time, @assert, @inbounds)
In Plain English
Julia ships with powerful built-in macros: @show for inspection, @time for memory and CPU benchmarking, @assert for runtime checks, and @inbounds for disabling array bounds checks.
Deep Dive: How It Works
@show: Prints expression label and its evaluated value.
@time: Measures execution time, garbage collection time, and memory allocated in bytes.
@elapsed: Returns elapsed seconds as a Float64 number for programmatic measurement.
@assert: Throws an AssertionError if condition is false.
@inbounds: Disables array bounds checks in performance-critical inner loops.
Core Rules to Remember

@time Benchmarking: Measures CPU time, % GC time, and total bytes allocated.

@assert Verification: Validates preconditions during development and unit testing.
Live Interactive Example
Hit Run Code to see it liveDiagnostic Macros in Action
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
Output Console
Click "Run Code" to view the rendered output.
How it works: @elapsed returns the precise execution duration in seconds.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Assert Condition and Show Variable
Set `core_count = 16`.
Use `@assert core_count >= 8`.
Print `"Cores verified: $core_count"`.
1
2
3
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.