In the process of trying to learn ODIN I think it’s going quite well. Most things I’ve been able to solve without too much trouble.
The following has me stumped. I want to calculate the time it takes to complete a whole heap of PROCs but I can’t figure out how to subtract the start time from the end time.
package main
import "core:fmt"
import "core:time"
main :: proc() {
start_time := time.duration_nanoseconds
//Call all sorts of proc's here
end_time := time.duration_nanoseconds
time_difference := end_time - start_time
fmt.println("Time difference in Nanoseconds:", time_difference)
}
I keep getting the following error, probably me being so new at this and missing something straight forward.
Error: Operator '-' is only allowed with numeric expressions
time_difference := end_time - start_time
time.duration_nanoseconds is a proc that you would use to turn a time.Duration into the number of nanoseconds it represents. So start_time and end_time are just proc pointers, since you’re not calling it.
To get a Duration for measuring time taken to do something, you’d probably want to use time.tick_now to get the Tick at the start, then time.tick_since to get the Duration since the starting Tick at the end. Then you could use time.duration_nanoseconds to get the number of nanoseconds between the two points.
So:
main :: proc () {
start_time := time.tick_now()
// do stuff
elapsed := time.tick_since(start_time)
fmt.println("Time difference:", elapsed) // prints with units appropriate for how long the time is
elapsed_ns := time.duration_nanoseconds(elapsed)
fmt.println("Time difference in nanoseconds:", elapsed_ns) // prints as a plain number
}
Notice that fmt knows how to format a time.Duration correctly (though on Windows, you might run into an issue with µ not being displayed correctly).
Thanks so much all working now… I generally like to try and find the answer myself. I think that is the best way to learn. I’ve been stuck on this one for hours. Had to thrown in the towel on this one.
While looking into the package documentation website is really nice and helpful, I want to emphasize one thing to the OP: You have the standard library on your computer. In my case, I just type subl /path/to/project /path/to/odin-2026-07 to open a project in Sublime and also the Odin installation. That means I have all my source files available and all of Odin’s standard library as well. When there is anything I need to look up, I can search for it without ever leaving the editor. Just speaking for myself, this is a game changer.