Ruby and other languages

Ruby anyone? :wink:

require "prime"
Prime.each(2000000).reduce(0, :+)
1 Like

Woah. Basically 1 line of code :slight_smile:

There’s a bunch of math functions in Swift too that seem to make this kind of thing super easy.

I’m going to have to dig up some non-math challenges or puzzles.

but ruby is very heavy on the CPU because it has lots of libraries.

As with many scripting languages, libraries load as needed. Speed wise it’s no different really than Python or PHP. They even share many JIT feature implementations. There was certainly a time when there were big speed differences between scripting languages, but now they’ve all adopted more or less the same strategies for their compilers. I think most of these scripting languages can even been compiled and have their binaries deployed for even faster execution. Facebook actually built these functionality for PHP. JavaScript is even incredibly fast, again, adopting very similar approaches to JIT design and more or less shared across web browsers these days.

That all being said, if it’s performance you’re after, you should be working in C or C++. However, it honestly doesn’t matter too much these days. Generally, if a customer of your code notices a slow down, it’s almost always because of poor implementation on the programmer’s part and not from due to the raw speed of the language the programmer decided to use.

Yeah, speed doesn’t mean much in these problems. And “heavy on the CPU” ? That’s what the CPU is for… next you’re going to tell me that it uses RAM. :slight_smile:

So what do you think of the A12 chip using those ARM instructions that make Javascript-like languages run faster?

If you told me 20 years ago that one day we’d be designing chips to better run certain languages, I’d laugh. But here we are :slight_smile: I guess GPUs have always been doing this, as well as certain ASICs. I know there are cryptocurrency ASICs, but there are now “networking” ASICs that are optimized for the computations necessary for layer 2 switching or layer 3 routing.

It is funny when we put it like that, but yeah, the instruction set of a CPU should be in service of what the average customer needs. I mean, that’s why we have so many instructions to work with. I guess your average customer uses the Web. :wink:

Time to break out the RISC versus CISC debate like it’s 1999!

1 Like

2 Likes

Kids will never know the torment of being a “hacker” in the 80s and 90s.

Bad hair, horrible bandwidth, standard-definition video on VHS. Worst of all, dreaming of Angelina Jolie when she was a Manic Pixie Dream Girl™️ and then waking up all confused.

Wait, that’s actually a scene in that movie, isn’t it?

2 Likes

lol! I literally LOL’ed.