Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v with tcc is 70x slower than using gcc with -prod #23095

Closed
gshields opened this issue Dec 7, 2024 · 7 comments
Closed

v with tcc is 70x slower than using gcc with -prod #23095

gshields opened this issue Dec 7, 2024 · 7 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@gshields
Copy link

gshields commented Dec 7, 2024

Describe the bug

native v is 70x slower than using gcc

Reproduction Steps

using gcc

cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc -std=gnu99 -w -o v1.exe ./vc/v.c -lm -lpthread
./v1.exe -no-parallel -o v2.exe cmd/v
./v2.exe -nocache -o ./v cmd/v
rm -rf v1.exe v2.exe
Your tcc is working. Good - it is much faster at compiling C source code.
V has been successfully built
V 0.4.8 11dc600
starting to compile nbody
-0.169075164
-0.169059907

real 0m3.136s
................................
using native v

cd ./vc && git clean -xf && git pull --quiet
cd ./thirdparty/tcc && git clean -xf && git pull --quiet
cc -std=gnu99 -w -o v1.exe ./vc/v.c -lm -lpthread
./v1.exe -no-parallel -o v2.exe cmd/v
./v2.exe -nocache -o ./v cmd/v
rm -rf v1.exe v2.exe
Your tcc is working. Good - it is much faster at compiling C source code.
V has been successfully built
V 0.4.8 11dc600
starting to compile nbody
-0.169075164
-0.169059907

real 1m22.120s
user 1m21.749s
sys 0m0.209s

Expected Behavior

v compiler shoudl be as fast as gcc

Current Behavior

V compiler 70X slower

Possible Solution

unknown

Additional Information/Context

No response

V version

Current V version: V 0.4.8 11dc600

Environment details (OS name and version, etc.)

V full version: V 0.4.8 e32e9f7.11dc600
OS: linux, Ubuntu 24.10
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz

getwd: /home/ghs/bin
vexe: /home/ghs/work/v/v
vexe mtime: 2024-12-07 19:23:51

vroot: OK, value: /home/ghs/work/v
VMODULES: OK, value: /home/ghs/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.45.2
Git vroot status: weekly.2024.49-34-g11dc6005
.git/config present: true

CC version: cc (Ubuntu 14.2.0-4ubuntu2) 14.2.0
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Huly®: V_0.6-21533

@gshields gshields added the Bug This tag is applied to issues which reports bugs. label Dec 7, 2024
@JalonSolov
Copy link
Contributor

Where is the nbody code you're compiling?

What command lines did you use?

@gshields
Copy link
Author

gshields commented Dec 7, 2024 via email

@enghitalo
Copy link
Contributor

I install v into ~/work/v
The nobody.v ia part of the examples
I navigate to the folder
cd ~/work/v/examples/

Then I run
-prod -cc gcc nbody.v

and then test it with
time ./nbody

I compared using the same process except using
v nbody.v
which is slower

On Sat, Dec 7, 2024 at 1:26 PM JalonSolov @.***> wrote:

Where is the nbody code you're compiling?

What command lines did you use?


Reply to this email directly, view it on GitHub
#23095 (comment), or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AA2NZI2OQ45WJ2VBHL444JL2ENRZPAVCNFSM6AAAAABTGPKIAGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMRVGMYTKNBVGQ
.
You are receiving this because you authored the thread.Message ID:
@.***>

I may be wrong. But I think you're confusing things a bit. There are a few different types of V compilation, for example, native, TCC, and GCC. TCC tends to be fast to compile, however, it does not generate as optimized machine code as GCC. To compile using GCC, try using the tag -prod

@JalonSolov
Copy link
Contributor

Correct. This doesn't have anything to do with V, but with the C compiler used on the backend.

Compiling without -prod makes V compile the output with tcc, which does almost NO optimization of the code.

Compiling with -prod will make V compile using msvc (on Windows), gcc, or clang, whichever you have installed as the default compiler, and both of them do very heavy optimizations. You can tell this by how much longer it takes to compile with -prod vs how quick it happens without.

With the optimizations, I'm not at all surprised that the code is a lot faster when compiled with -prod than it is without.

Lastly, V does have an actual native backend, but it is incomplete, and cannot compile very much V code successfully, yet. When I try to compile with the -native option, I get

$ v -native nbody.v
native error: Unhandled os ifdef name "fast_math".
$

so it won't even compile to test against the C compiled versions.

Comparing the C versions against, each other, though, I get this on my machine:

$ hyperfine ./nbody_tcc ./nbody_gcc ./nbody_clang
Benchmark 1: ./nbody_tcc
  Time (mean ± σ):     37.757 s ±  0.580 s    [User: 37.696 s, System: 0.023 s]
  Range (min … max):   37.081 s … 38.449 s    10 runs
 
Benchmark 2: ./nbody_gcc
  Time (mean ± σ):      1.961 s ±  0.008 s    [User: 1.959 s, System: 0.000 s]
  Range (min … max):    1.954 s …  1.975 s    10 runs
 
Benchmark 3: ./nbody_clang
  Time (mean ± σ):      2.694 s ±  0.405 s    [User: 2.688 s, System: 0.003 s]
  Range (min … max):    2.498 s …  3.462 s    10 runs
 
Summary
  ./nbody_gcc ran
    1.37 ± 0.21 times faster than ./nbody_clang
   19.26 ± 0.31 times faster than ./nbody_tcc
$

@spytheman
Copy link
Member

I think the confusion stems from the use of the term native.

V has a native backend, but it is incomplete. You can choose it with -b native.

It also downloads and uses a tcc executable by default, since it is a small and fast C compiler, which however does not optimise.

Imho the title should be changed to reflect that, and the word native should be removed, replaced by v by default with tcc.

@JalonSolov JalonSolov changed the title native v is 70x slower than using gcc v with tcc is 70x slower than using gcc with -prod Dec 8, 2024
@JalonSolov
Copy link
Contributor

Title changed. Closing.

@gshields
Copy link
Author

gshields commented Dec 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

4 participants