Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Project Euler and Software Optimization (Problem 4 & Palindromes)

#4
(February 12th, 2020 at 5:37 AM)Darth-Apple Wrote: Actually, I wondered about this. It wouldn't make much of a difference. It literally records the current time (to the millisecond level) at the start of the script, and then records it as soon as it finds a palindrome. It only tests for the time maybe six or seven times throughout the whole script execution (which maybe adds up to about 0.1 seconds at most). In other words, it does add considerable time for very small tests, but once you start checking 7+ digits, it's neglible compared to the rest.

And what you've mentioned about rust has me wanting to try it. Python is absolutely not the language to be using for this sort of thing. Multithreading and PyPy helped, but it's still python.

Incidentally, I tried out Cython recently. It's python, but you simply have to declare your types for functions and variables. And boy, oh boy, is it faster. On the order of about 20 times faster. It might just be my go-to from here on out. Finna

Ah, fair enough on the timing thing. I figured you'd be running into way more palindromes than that to make it worthwhile.

And mind you, Rust has one hell of a learning curve. Coming from a predominantly C-oriented background, it really screwed with me, like the concept of shadowing variables and everything being a const by default unless you add &mut to everything that you're going to be changing a lot. Not to mention Result<t> or Option<t> wrappers which although make for safer code and easier handling of errors, I was used to the classic 'retrieving error messages from memory using pointers to where the function f*** up' as OpenGL loves to do in C++.

Also yeah Cython is based, especially just loading C code into Python through its wrapper. Yeah, implicit interpretation of variables can get really f*** timing-wise, just look at how badly JS performs compared to literally anything else. At least with Python you don't get shit like this:
Code:
console.log('5' + 3); // prints 53
console.log('5' - 3); // prints 2

//Go on, open your browser console, I know you want to try it...

And you'll run into the occasional type error like if you ran:
Code:
num = input()
print(num + 3)
# str + int = not allowed :(
Since at least it does differentiate between types instead of implicitly just using them how it seems fit.

But with less processing put towards interpretation, more processing goes towards your actual logic to make stuff fast. Definitely pick up a native language if you're interested in making fast code. Seems you have a really good handle on programming/logic/Python already so it's the natural next step.
Reply


Messages In This Thread
RE: Project Euler and Software Optimization - by Lain - February 12th, 2020 at 5:25 AM
RE: Project Euler and Software Optimization - by Darth-Apple - February 12th, 2020 at 5:37 AM
RE: Project Euler and Software Optimization - by Lain - February 12th, 2020 at 6:21 AM
RE: Project Euler and Software Optimization - by Darth-Apple - February 12th, 2020 at 7:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Optimization and You Lain 6 7,370 September 25th, 2019 at 5:46 PM
Last Post: SpookyZalost



Users browsing this thread: 2 Guest(s)

Dark/Light Theme Selector

Contact Us | Makestation | Return to Top | Lite (Archive) Mode | RSS Syndication 
Proudly powered by MyBB 1.8, © 2002-2024
Forum design by Makestation Team © 2013-2024