mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin,strconv: speedup str.int()
conversions (without -prod)
This commit is contained in:
17
vlib/v/tests/bench/bench_string_int.v
Normal file
17
vlib/v/tests/bench/bench_string_int.v
Normal file
@@ -0,0 +1,17 @@
|
||||
import benchmark
|
||||
|
||||
const maxn = 999_999
|
||||
|
||||
fn main() {
|
||||
mut snumbers := []string{cap: maxn}
|
||||
for i in 0 .. maxn {
|
||||
snumbers << i.str()
|
||||
}
|
||||
mut sum := i64(0)
|
||||
mut bmark := benchmark.start()
|
||||
for s in snumbers {
|
||||
sum += s.int()
|
||||
}
|
||||
bmark.measure('s.int()')
|
||||
dump(sum)
|
||||
}
|
@@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
[direct_array_access]
|
||||
fn test_big_int_array() {
|
||||
dump(sizeof(isize))
|
||||
@@ -5,6 +7,11 @@ fn test_big_int_array() {
|
||||
if sizeof(isize) > 4 {
|
||||
maxn = 1_000_000_000 // 1 billion integers, when each is 4 bytes => require ~4GB
|
||||
}
|
||||
// NB: this test requires RAM that many people do not have, so only run it in full, when VTEST_BIGMEM is 1
|
||||
vtest_bigmem := os.getenv('VTEST_BIGMEM').int()
|
||||
if vtest_bigmem == 0 {
|
||||
maxn = 10_000_000
|
||||
}
|
||||
dump(maxn)
|
||||
mut data := []int{len: maxn}
|
||||
|
||||
|
Reference in New Issue
Block a user