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 when the program exits, which you can then
analyze. If the output file is omitted, as in v -profile run file.v, the report
is written to standard output. -prof is an alias for -profile.
The V3 compiler supports profiling with its C backend. Other V3 backends reject
-profile. V3 also supports these V1-compatible selection options:
-profile-fns name1,name2profiles only the named functions and functions called from them. Use the function names shown in profile output, such asmain__work.-profile-no-inlineomits functions marked@[inline]from the report.-d no_profile_startupexcludes calls made during module initialization.
Use the selection options together with -profile. The generated profile file
has lines with 5 columns:
- How many times a function was called.
- How much time in total a function took (in ms).
- How much time a function took (in ms), on its own, without the calls inside it. It is reliable for multithreaded programs, when tcc is not used.
- How much time on average, a call to a function took (in ns).
- The name of the v function.
You can sort on column 3 (exclusive time per function) using:
sort -n -k3 profile.txt | tail
You can also use stopwatches to measure just portions of your code explicitly: