Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 453 454 [455] 456 457 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 817667 times)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6810 on: December 30, 2014, 04:55:19 am »

This is just a guess, but I think it's very possible that that's a design issue rather than something inherent to Python. Have you tried profiling your program to find the bottlenecks?
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #6811 on: December 30, 2014, 04:57:53 am »

It's very definitely inherent to Python. My mother was at one stage working through the Project Euler problems, and a lot of them she was struggling with because Python wasn't solving them in under a minute. It's optimisable, but you have to optimise C and C-based languages a lot less.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6812 on: December 30, 2014, 05:15:35 am »

How do you know without seeing Hat's code, though? For all you know, it might be blocking somewhere, or some incorrect design like (wild example) iterating over an unsorted list to find stuff.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #6813 on: December 30, 2014, 05:17:56 am »

Fair enough. Performance in Python does tend to brick-wall pretty easily, though.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6814 on: December 30, 2014, 05:27:06 am »

Python is interpreted, isn't an interpreted language almost always slower than a compiled language? (Especially if the compilers are as advanced as those of C and C++ are)
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6815 on: December 30, 2014, 06:02:28 am »

Yes, but it's also possible that merely changing a design will speed it up by orders of magnitude. Rewriting things in a different language is usually a last-resort.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6816 on: December 30, 2014, 06:30:03 am »

Not when you're talking about interpreted languages. If it's some toy problem, sure, but if you want it to scale you need to run on bare metal code eventually.

Uristides

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6817 on: December 30, 2014, 06:52:09 am »

The problem with passing a char[4][8] as a char ** is that a two-dimensional static-sized array is not implemented as a (char *)[], with pointers for each actual string. it's actually implemented as a single char[32] and the compiler converts all your indexes to that. So the "under the hood" implementation is actually different to manually making a (char *)[4]  then assigning each (char *) to a memory location containing a string. This version shows how it works (tested with VC++ 2012).
[...]
orz, sorry for that then ed boy. Thanks for explaining where I went wrong Reelya.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6818 on: December 30, 2014, 06:55:07 am »

Not when you're talking about interpreted languages. If it's some toy problem, sure, but if you want it to scale you need to run on bare metal code eventually.
While I disagree, I don't think this discussion can end without an "Agree to disagree" sort of deal... :P
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6819 on: December 30, 2014, 07:50:45 am »

It's not a matter of opinion though. Benchmarks of the best-known Python implementation are much slower than the best-known c++ ones:

http://benchmarksgame.alioth.debian.org/u32q/benchmark.php?test=all&lang=python3&lang2=gpp&data=u32q

For some algorithms, the fastest-known Python implementation is ~100 times slower than c++. So in other words, you don't use Python for anything that needs CPU cycles. Stuff that doesn't do any processing and has plenty of idle time won't hurt to run in Python though.
« Last Edit: December 30, 2014, 07:59:01 am by Reelya »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6820 on: December 30, 2014, 07:57:34 am »

But I'm not comparing Python to C++.

What I (meant to) said is

It may be possible that algorithm optimizations will be as good as switching to C++, relatively.

Consider:

Python/Bad algorithm, time 10000
Python/Optimizaed algorithm, time 1000
C++/bad algorithm, time 1000
C++/good algorithm, time 100

I don't doubt that C++ is faster than Python, but I'm saying that you should consider optimizing your code theoretically before switching to C++. It's also less work than rewriting a system in a new language.

edit: Maybe the optimized algorithm is only x2 faster. But there's still the relative productivity of fixing an algorithm compared to rewriting your entire code in another language. :I
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6821 on: December 30, 2014, 08:01:01 am »

But optimizing something twice is wasted effort. Optimizations that work well in Python will have to be undone to make it a good C++ program. It makes a lot more sense to port a non-optimized easy to understand version then optimize it in c++. If you're after maximum performance with minimal work, this is the way to do it. And a program that computes astronomical simulation data - you can always find a use for higher performance.
« Last Edit: December 30, 2014, 08:03:39 am by Reelya »
Logged

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6822 on: December 30, 2014, 08:20:58 am »

It may be that the code in question is not efficient. For example, it could be some horrible brute-force pathfinding algorithm that could simply be replaced with a Python A* implementation. Rewriting the brute-force code in C++ will still be slower than the A* python code for any significant sized problem, and it is possible that the size of the problem is still sufficiently small that it can be solved by the Python A* code fast enough to be acceptable. (I think that Skyrunner was referring to something like this, optimising the algorithm, not the code (I think?)).

(It is EnigmaticHat and their complete-mystery game we are talking about, right?)
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6823 on: December 30, 2014, 08:37:50 am »

Yes, that was what I meant to say :( My lack of communication skills is going to bite me later..
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6824 on: December 30, 2014, 04:04:55 pm »

I wanted to learn C++ anyway guys, this was just a convenient excuse.  No need to have an argument about it.

Anyway, I'm working on two games, one of which is my main project that I'm fairly certain can be made exclusively in Python (it currently runs decently on my fairly shitty laptop, and tech is only going to get better over time).  It started in the Roguelike Development Megathread but now is more of a TBS game than a roguelike.  The other one, which is more me dicking around to see what I can do than a serious project I intend to finish anytime soon, involves generating terrain maps for alien planets:
Spoiler: like this one (click to show/hide)
This one took only about 2 seconds to generate, most of which is defining the damn province borders (which I have still not perfected, you'll notice a bunch of tiny provinces in other provinces).

The problem is two-fold.  First, this map is supposed to be one of many across a larger galaxy, and secondly, the game draws each map pixel by pixel so that I can do things like different mapmodes and highlighting provinces.

Now, do you know how many frames per second you get when you ask python to generate arrays with tens of thousands of entries and then draw a map based on them pixel by pixel?  Less than one.  Not good.
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule
Pages: 1 ... 453 454 [455] 456 457 ... 795