<hexology>
performance improvements as well, on 30 million rows cpython is finishing in ~4 seconds and ruby 3.2 with yjit enabled is finishing in ~6 seconds
<hexology>
i assume this `def main` isn't entirely idiomatic, but i wasn't sure
<hexology>
i suspect that cpython cheats and just uses a much larger stdin buffer than the other runtimes it surprisingly beats (e.g luajit, common lisp), but i'm not sure how i'd check that. is there a way to see the size of the stdin buffer in ruby?
_ht has joined #ruby
reset has joined #ruby
moldorcoder7 has joined #ruby
libsys has joined #ruby
goldfish has joined #ruby
cek has joined #ruby
rvalue has quit [Read error: Connection reset by peer]
<libsys>
where does the guy from socketry hang out? I'd like to ask him about the usage of rubydns or async-dns
<libsys>
specifically, if I should use rubydns or async-dns for new projects heh
aesthetikx has quit [Ping timeout: 240 seconds]
rvalue has joined #ruby
___nick___ has joined #ruby
aesthetikx has joined #ruby
leftylink has quit [Quit: leaving]
leftylink has joined #ruby
Sankalp has quit [Ping timeout: 268 seconds]
Sankalp has joined #ruby
cek has quit [Quit: Connection closed for inactivity]
SunClonus has quit [Read error: Connection reset by peer]
goldfish has quit [Quit: Leaving]
lena64t has joined #ruby
tomtmym has quit [Quit: Gone.]
Sankalp has quit [Ping timeout: 240 seconds]
gr33n7007h has quit [Ping timeout: 248 seconds]
teclator has quit [Ping timeout: 268 seconds]
Sankalp has joined #ruby
gr33n7007h has joined #ruby
<mooff>
hexology: that's a pretty straight translation of the Python into Ruby
<mooff>
surprising that cpython beats luajit..
roadie has quit [Ping timeout: 248 seconds]
<mooff>
can i see the lua?! lol
<hexology>
mooff: unabashedly so :) i did however benefit from rubocop's suggestions in removing the extraneous being/end inside the do blocks.
<hexology>
i think i might have lost track of the lua version i had a while ago. the logic was basically the same but i don't know if i was reading from stdin correctly
<mooff>
the equivalent of if __name__ == "__main__" in Ruby is if __FILE__ == $0
<hexology>
thanks. is that idiomatic or is it just me transliterating python to ruby syntax?
<mooff>
what do you mean by "that"?
<hexology>
putting "if __FILE__ == $0 \n main \n end" in a script
ur5us has joined #ruby
<ox1eef_>
It is the normal way to detect if the script being executed is the same script given to Ruby at the command line. But not once did I ever need that.
<mooff>
it's not terribly common to see such a main method defined, but it seems fine
<Momentum>
hi folks
<ox1eef_>
I often define name for CLI tools.
<ox1eef_>
s/name/main/
<ox1eef_>
o/ Momentum
<hexology>
thanks all
<Momentum>
hi ox1eef_ good to see you
roadie has joined #ruby
<ox1eef_>
You too :)
<Momentum>
the ruby package on arch has been stuck on 3.0.5 for a while
<hexology>
it's usually not needed in python, but it's become idiomatic "just in case" you also want to import things from your module in other code, e.g. for calling functions in a test suite
<mooff>
hexology: how many lines does it process during the benchmark?
<Momentum>
should i use RVM? or there's a better way?
<ox1eef_>
That's unusual for Arch.
<Momentum>
yeah
<Momentum>
they seem to be aware of it though
FetidToot5 has joined #ruby
<weaksauc_>
rbenv i like more Momentum
<mooff>
surprised you don't get updates from every commit to Ruby trunk on Arch :P
<weaksauc_>
if not that then i'd probably invest time in asdf
m_antis_ has joined #ruby
<ox1eef_>
chruby / ruby-install is what I'd generally recommend. Personally I compile from scratch.
<Momentum>
nice mix of options
NightMonkey_ has joined #ruby
<weaksauc_>
technically ruby-install compiles from scratch doesn't it?
<Momentum>
how long does the compiling from source take i wonder?
<ox1eef_>
I think so. But not sure.
<ox1eef_>
15 minutes maximum.
<weaksauc_>
not very long Momentum
<Momentum>
manageable
<weaksauc_>
i think last time it was like 10 min
<hexology>
i installed 3.2.2 with rbenv the other day and it only took a few minutes, but i'm on a powerful machine
<weaksauc_>
but i didn't time it and forgot about that tab for a while
<ox1eef_>
./configure --prefix=$HOME/.rubies/3.2.2; make; make install - then add $HOME/.rubies/3.2.2/bin to $PATH
<hexology>
mooff: 30m lines, of which ~900k are blank (matching ^\s*$)
<ox1eef_>
You definitely don't need tooling for it but it can be nice and easier to manage
<Momentum>
thanks ox1eef_ i will try that
<Momentum>
i should create the directory, right?
roadie has quit [Ping timeout: 248 seconds]
<Momentum>
~/.rubies that is
<ox1eef_>
Check out --program-suffix too. If you have multiple versions, and don't want to rely on shell shims, it can be helpful. And yeah, can't hurt to do that.
<mooff>
hexology: interesting. want to try a modification?
<mooff>
rather than $stdin.each_line do |line| ..
<ox1eef_>
You could also use chruby alone with that setup, where you're compiling rubies in ~/.rubies/X.X.X
<hexology>
mooff: yes please!
<mooff>
try: while line = $stdin.readline
<mooff>
that's LESS idiomatic, but may run faster
Demi_ has joined #ruby
<hexology>
mooff: interesting, why would it be faster? also, would i need to add an explicit `begin` inside the loop, right?
<Momentum>
alright ox1eef_
<mooff>
hexology: yes, i believe it would need an explicit "begin", then
<Momentum>
not familiar with chruby so i will have to check that
admin2 has joined #ruby
<ox1eef_>
It is focused on switching ruby versions in your shell environment, and does not do more than that (eg installing rubies).
roadie has joined #ruby
<weaksauc_>
Momentum chruby is fine but it can run into some issues with some tooling
ur5us has quit [*.net *.split]
tweaks has quit [*.net *.split]
m_antis has quit [*.net *.split]
dostoyevsky2 has quit [*.net *.split]
FetidToot has quit [*.net *.split]
cybniv has quit [*.net *.split]
heartburn has quit [*.net *.split]
CalimeroTeknik has quit [*.net *.split]
NightMonkey has quit [*.net *.split]
pavelz has quit [*.net *.split]
Demi has quit [*.net *.split]
Vonter has quit [*.net *.split]
bastelfreak has quit [*.net *.split]
roger_rabbit has quit [*.net *.split]
Fridtjof has quit [*.net *.split]
FetidToot5 is now known as FetidToot
<weaksauc_>
i find that the shim approach works better with tools like vscode
NightMonkey_ is now known as NightMonkey
infinityfye has quit [Quit: Leaving]
<Momentum>
i see
<mooff>
hexology: method / block calls are relatively slow in Ruby
<ox1eef_>
Of all those tools, I believe postmodern got it right. One tool, one responibility.
<weaksauc_>
technically ruby-install is separate from rbenv
<mooff>
although #each (which calls a block for each item) is by far the most common way to iterate in Ruby, with high iteration counts, the block calls themselves add up
<weaksauc_>
while doesn't create a new scope
<Momentum>
i actually used rbenv before, seemed like a pretty solid tool i almost thought it was something official
<ox1eef_>
The evolution was: RVM -> rbenv -> chruby. And I think chruby learnt from the mistakes of the past.
<Momentum>
sounds good
shokohsc0 has joined #ruby
<Momentum>
okay ruby-install along with chruby seems pretty good for me
shokohsc has quit [Ping timeout: 246 seconds]
shokohsc0 is now known as shokohsc
<Momentum>
this is also better than relying on arch packages even though i wasn't planning to install multiple versions
<mooff>
hexology: pardon me, you want $stdin.gets rather than $stdin.readline
<hexology>
thanks
<ox1eef_>
I rely on my system's package manager and a custom port (at least on FreeBSD where their default ruby installation is butchered).
<mooff>
($stdin.readline is the same as $stdin.gets, except it raises EOFError on eof)
<mooff>
tested here and the change described works
<hexology>
ox1eef_: i've been using rbenv because i'm very familiar with pyenv, which is apparently based on rbenv. what does chruby improve on?
<hexology>
the asdf version manager has also become popular, but that's largely because it's able to handle *any* program with a plugin system. from what i remember, it works very similar to pyenv/rbenv
<hexology>
mooff: good to know. i assume exception handling also has some additional overhead?
<ox1eef_>
I prefer chruby's interface, and its ability to co-operate with other tools - which comes from doing one thing well.
<mooff>
hexology: i think it does, but i haven't measured it
<hexology>
ox1eef_: thanks. i'll look into it, happy to learn from other people's good ideas
<ox1eef_>
Time is precious !
<mooff>
you might even get a better treatment from the JIT if you can avoid exceptions
<mooff>
something like "x = line.to_f", then "if x == 0.0; # check for blank/invalid line" might be optimal
<weaksauc_>
that doesn't really give you the ability to use 0.0 in your data though
<weaksauc_>
which would skew it
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
<mooff>
yeah, you'd need to let valid 0.0's through
<mooff>
sort of micro-optimising for the benchmark