Tools

v fmt

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

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.

Disabling the formatting locally

To disable formatting for a block of code, wrap it with // vfmt off and // vfmt on comments.

// Not affected by fmt
// vfmt off

... your code here ...

// vfmt on

// Affected by fmt
... your code here ...

v shader

You can use GPU shaders with V graphical apps. You write your shaders in an annotated GLSL dialect and use v shader to compile them for all supported target platforms.

v shader /path/to/project/dir/or/file.v

Currently you need to include a header and declare a glue function before using the shader in 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:

  1. How many times a function was called.
  2. How much time in total a function took (in ms).
  3. How much time on average, a call to a function took (in ns).
  4. 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:

import time fn main() { sw := time.new_stopwatch() println('Hello world') println('Greeting the world took: ${sw.elapsed().nanoseconds()}ns') }
On this page