Tools

v fmt

You don’t need to worry about formatting your code or setting style guidelines. v fmt takes care of that:

  1. v fmt file.v

It’s recommended to set up your editor, so that v fmt -w runs on every save. A vfmt run is usually pretty cheap (takes <30ms).

Always run v fmt -w file.v before pushing your code.

Profiling

V has good support for profiling your programs: v -profile profile.txt run file.v That will produce a profile.txt file, which you can then analyze.

The generated profile.txt file will have lines with 4 columns: a) how many times a function was called b) how much time in total a function took (in ms) c) how much time on average, a call to a function took (in ns) d) the name of the v function

You can sort on column 3 (average time per function) using: sort -n -k3 profile.txt|tail

You can also use stopwatches to measure just portions of your code explicitly:

  1. import time
  2. fn main() {
  3. sw := time.new_stopwatch({})
  4. println('Hello world')
  5. println('Greeting the world took: ${sw.elapsed().nanoseconds()}ns')
  6. }

Advanced Topics