-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
strings need an efficient way to check if they contain a char #17698
Comments
On my machine: V
Go
3.7 times slower, probably due to Go's more efficient goroutines. We're getting those soon. You're most likely not using clang/msvc when doing prod builds. Run
|
Here's the output. Additional information: I am on Windows 11 and Intel i7-10750H.
|
So you are using msvc. Could be an msvc thing. Can you try to install clang (V's docs have info on how to do it) and try with |
On Windows you can also get AV scanners during program runtime. We had lots of slowdowns reported because of that. It's best to benchmark on non Windows systems. |
Clang performed slightly better at ~7369 ms but still too slow when compared to Go’s ~55ms. I began testing yesterday and still getting the same results today after a computer restart. I don't have any other AVs installed other than Windows Defender.
|
very weird if you have a linux vm/machine, please try there |
On my Linux machine V (-cc clang -prod) took 1324ms while go took 179ms |
Tried on a linux mint usb and with |
It's definitely the antivirus then. |
It is silly sugest, but try |
I initially tried with autofree and it gave a C compiler error, so I let it fall back on the gc |
Upon further debugging, I might've found the partial culprit (at least on my windows machine). I have to specify For reference here are the outputs of Without
With
Also I would like to note that while debugging this, I found out that the latest version of clang and gcc from this site does not work with V. Also some versions have a working clang but non working gcc, while others have vise versa. I have yet to find a version with both gcc and clang working. Eventually I just scrapped clang and gcc and just stuck with msvc. This is when I found out about this bug that specifying |
Just curious, what is the content of Edit: just saw that you linked it - https://ghostbin.me/641574ba443d6 . |
The problem has nothing to do with channels. fn contains_char(s string, c u8) bool {
for x in s {
if x == c {
return true
}
}
return false
} and then: If I use the above, instead of
i.e. the V version becomes faster than the Go one. I think we just need to add the above specialized function as a string method too, for searching a single byte in a string, potentially returning its index, instead of a bool. Alternatively, we can add that as a special case for the already existing |
Here is the faster version for your amusement :-) |
Wow! Combining |
Thanks @spytheman, I missed that. I assume it's because you're running It does an allocation for each new string. |
what's the error you're getting? |
Implemented in #17702 . |
To use Edit: @medvednikov already guessed the reason. |
That's handy to know. Thank you! I hope I'm not steering too far away from the issue but is
GCC 12.2.0 + LLVM/Clang/LLD/LLDB 15.0.7 + MinGW-w64 10.0.0 (UCRT) - release 4
GCC 11.3.0 + LLVM/Clang/LLD/LLDB 14.0.3 + MinGW-w64 10.0.0 (UCRT) - release 3
GCC 10.3.0 + LLVM/Clang/LLD/LLDB 12.0.0 + MinGW-w64 9.0.0 (MSVCRT) - release 2
|
No, |
|
well in this example which didn't seem to be the case |
From that, I think that the left part (the one for I think that the conditional compilation depends on evaluating msvc based on the passed compiler option, not on what exact compiler was chosen (due to Imho that is one more reason to dislike guessing, and the fact that currently |
Anyway, that is something for another issue. I think that the current one can be closed when the PR is merged, @rcsaquino ? |
Yes the initial issue has been fixed. The issue with Cheers! |
May I suggest a change in title or a less dramatic one? Not saying there isn't an issue somewhere, but present title doesn't reflect what it is or can be considered misleading. Just happen to do a Google/Bing search, for the week on Vlang, and this popped up at the top. Skim through this, and it appears that simple changes to how it's written or use of |
Done @Wajinn |
s := 'this is a string with !'
y := `!` in s.runes()
println(y) seems pretty quick... |
Describe the bug
The way I learn concurrency when experimenting with new programming languages is by rewriting a code I've made in the past which is supposed to calculate the best word to guess based on the words listed on an online game called wordle. This is the V code and this is the Go code. I've experimented with the code a lot but found no way of improving the efficiency of the V code without changing the code much.
On my machine, V code executes ~8164 ms while the Go code executes ~56ms. Repeated runs shows ~145x slower V code than Go.
Expected Behavior
I expect V to be faster than Go. If not, they at least should be on par.
Current Behavior
V code performs significantly worse (~145x slower) than Go code,
Reproduction Steps
Run V with
v -prod main.v
then run executablemain.exe
Run Go with
go run main.go
Possible Solution
No response
Additional Information/Context
Here's the json file needed to run the code if you want to do your own testing.
V version
V 0.3.3
Environment details (OS name and version, etc.)
V full version: V 0.3.3 d00237f.6e1e406
OS: windows, Microsoft Windows 11 Home Single Language v22621 64-bit
Processor: 12 cpus, 64bit, little endian,
getwd: C:\Users\user
vexe: C:\Users\user\v\v.exe
vexe mtime: 2023-03-17 19:02:20
vroot: OK, value: C:\Users\user\v
VMODULES: OK, value: C:\Users\user.vmodules
VTMP: OK, value: C:\Users\user\AppData\Local\Temp\v_0
Git version: git version 2.39.1.windows.1
Git vroot status: weekly.2023.11-18-g6e1e4062 (10 commit(s) behind V master)
.git/config present: true
CC version: Error: exec failed (CreateProcess) with code 2: The system cannot find the file specified.
cmd: cc --version
thirdparty/tcc status: thirdparty-windows-amd64 e90c2620
The text was updated successfully, but these errors were encountered: