This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
13:36 guifa joined 15:58 jgaz joined 17:08 jgaz left 18:27 n1to joined 18:28 n1to left 18:36 hearingtrumpet joined, hearingtrumpet left
.vushu shouldn't a rakumod run faster than simply in a raku file? 21:59
librasteve yes - typically it will be precompiled into bytecode 22:05
.vushu my $n; for 0..^1000000000 { $n +=1; } say $n; in raku file on my machine: 1000000000 real 0m57.473s user 0m57.247s sys 0m0.053s 22:06
in rakumod: 1000000000 real 3m17.518s user 4m21.418s sys 0m0.823s
librasteve well - i don't suppose the compiler spends much time on a 5 liner
.vushu So in this case the interpreter is faster 22:07
or how should I understand this
librasteve i'm not sure how the rakumod is so slow / different ... can you maybe post the code in a gist and I can try to repreoduce on my machine? 22:08
ok, I cc ed it 22:10
~ > time raku scum2.raku 1000000000 raku scum2.raku 88.60s user 0.27s system 99% cpu 1:29.20 total
that's a script, not a rakumod btw 22:11
.vushu gist.github.com/vushu/2c064b1d4cfc...2815c64c78 22:12
librasteve tx!
.vushu no problem, thx for investigating šŸ™‚ 22:13
librasteve 2nd pass the same ~ > time raku scum2.raku 1000000000 raku scum2.raku 88.72s user 0.23s system 99% cpu 1:28.99 total 22:14
now with the module: 22:15
in general, rakudo will precompile your code (.raku or .rakumod) to bytecode, hand it to MoarVM and then it gets run ... MoarVM has some support for introspection and jit optimisation 22:17
however, once a rakumod has been compiled once, a precomp file of the bytecode is retained and if there are no changes, the front end of the compilation is bypassed 22:20
none of this has any bearing on your code since it is a very short program with very short compile time, and then a very long execution time 22:21
anyway, my rakumod has now finished...raku -I'.' scum3.raku 193.15s user 19.50s system 108% cpu 3:16.52 total 22:22
so I conclude (i) my results are similar to yours, (ii) rakumod is 3x slower
.vushu Thanks for clarifying why, this happens. 22:23
Do you have en example where rakumod is indeed faster than the coressponding raku file? 22:24
librasteve ok, I have had a think about why your rakumod example is 3x slower ... I believe the situation is this: (i) when you use a rakumod file you are compiling and loading a raku module, (ii) while the main purpose of the module is to contain chunks of code that can be packaged and re-used, the use statement causes the compiler to run all code statements in the rakumod - why? well that's so that you can put in 22:31
code snippets to read config files, set up some constants and other hopefully lightweight tasks, (iii) then the main program runs. ... and, in the first pass, the module has to be compiled with (jit) optimisations turned off because [reasons I do not know but can guess]
so, in your example, your rakumod has a very short section of code, but it has very long runtime --- and so you are witnessing that the jit gives you a 3 x speed up when you run the main program 22:32
OK - for an example, go git clone github.com/librasteve/raku-Physics-Unit.git 22:33
then cd raku-Physics-Unit/bin && ./synopsis.raku 22:34
oops I mean time ./synopsis-unit.raku 22:36
./synopsis-unit.raku 4.73s user 0.10s system 115% cpu 4.202 total
that ^^^ includes the front end compile time 22:37
./synopsis-unit.raku 3.41s user 0.05s system 112% cpu 3.074 total 22:38
^^^ subsequent passes use the .precomp module and thus the time is lower
.vushu real 0m6.643s user 0m7.185s sys 0m0.105s I got from running time ./synopsis-unit.raku 22:40
First pass: real 0m8.465s user 0m9.880s sys 0m0.193s 22:42
Yeah it's faster
the subsequent ones
librasteve try going to /lib/Physics/Unit.rakumod line 20 and change constant \preload = 1; 22:44
oh - scrub that 22:45
.vushu ok :d 22:46
librasteve perl -e 'my $n; for my $i (0..100_000_000) {$n += 1}; print "$n\n"' 2.01s user 0.01s system 99% cpu 2.023 total 22:59
raku -e 'my $n; for ^100_000_000 {$n += 1}; say $n' 9.06s user 0.03s system 100% cpu 9.057 total 23:00
so perl is about 5x the speed of raku
perl takes 2.01s for 100_000_000 and 19.73s for 1000_000_000 = about linear 23:04
raku takes 9.06s for 100_000_000 and 89.31s for 1000_000_000 = about 10% speed up 23:05
.vushu perl is quite fast. 23:06
c++: int n = 0; for (int i = 0; i < 1000000000; i++) { n +=1; } std::cout << n << std::endl; real 0m1.908s user 0m1.907s sys 0m0.000s 23:13
lizmat librasteve my int $n; for ^100_000_000 {$n += 1}; say $n is about 2.75 seconds for me 23:33
and that would be a much better comparison, as perl is basically also using native ints
if you want to really compare with perl, you would need perl to use BigInts 23:34
23:46 tea3po left, tea3po joined
.vushu my int $n; for ^100_000_000 {$n += 1}; say $n takes for me : real 0m1.654s user 0m1.418s sys 0m0.051s where as my int $n; for ^1000_000_000 { $n +=1; } takes : real 0m11.959s user 0m11.677s sys 0m0.053s Isn't the code the same? 23:48
but the code is 10x faster with the oneliner
I don't understand 23:49