Computer Science Canada Trig calculations vs. lookup tables |
Author: | do_pete [ Fri Sep 15, 2006 9:30 am ] |
Post subject: | Trig calculations vs. lookup tables |
I'm planning on making a game in Python that includes lots of trigonometry. Should I invest in making lookup tables to increase the speed or would that not make a difference? |
Author: | [Gandalf] [ Fri Sep 15, 2006 2:20 pm ] |
Post subject: | |
I'm sure it would make at least a bit of a difference, though it really matters on how important speed and smooth execution will be in your game. In any case, I don't see why you shouldn't use them.. |
Author: | Cervantes [ Fri Sep 15, 2006 2:44 pm ] |
Post subject: | |
[Gandalf] wrote: In any case, I don't see why you shouldn't use them..
Because they use up memory. If you're already using lots, you should be careful about its use. If you want to be precise in the values you get, you'll have to use lots of memory to store that accuracy. |
Author: | bugzpodder [ Fri Sep 15, 2006 5:47 pm ] |
Post subject: | |
if you are worried about speed, then you shouldnt be using python. |
Author: | [Gandalf] [ Fri Sep 15, 2006 6:01 pm ] |
Post subject: | |
Cervantes, true that. Though really, in most cases 1 degree accuracy won't take up a huge amount of memory and still does the job. About speed... As far as I know Python seems like one of the better choices with regards to speed while still being beginner friendly. Ignoring O'Caml, that is. ;) |
Author: | zylum [ Fri Sep 15, 2006 6:46 pm ] |
Post subject: | |
isnt java faster than python? either way, unless you are doing thousands of trig calculations per loop, it shouldnt slow down your program too much. do some benchmarks. |
Author: | bugzpodder [ Sat Sep 16, 2006 1:12 pm ] |
Post subject: | |
python is an interpreted language. C/C++ is compiled into bytecode. Java sort of sits in a middle but its VM are optimized enough so that you won't see too much of a performance loss compared to C/C++ (although it is still present). You may want to try out IronPython on the other hand since it works the same way as all other .net languages by compiling to IL. |
Author: | wtd [ Sat Sep 16, 2006 1:16 pm ] |
Post subject: | |
C and C++ (and many other languages) are compiled into native machine code. Java and Python are compiled to bytecode which is interpreted. Or alternatively, the interpreting environment may Just-in-Time compile this bytecode to native machine code. |
Author: | bugzpodder [ Sat Sep 16, 2006 5:50 pm ] |
Post subject: | |
right, thats what i meant ![]() |
Author: | do_pete [ Tue Sep 19, 2006 9:33 am ] |
Post subject: | |
Okay, thanks for the help. If I need more speed for my program is it possible to integrate C/C++ programs into it? |
Author: | zylum [ Tue Sep 19, 2006 10:44 pm ] |
Post subject: | |
what exactly are you making that needs to that fast? |
Author: | bugzpodder [ Wed Sep 20, 2006 6:57 am ] |
Post subject: | |
Sure, use IronPython |
Author: | do_pete [ Wed Sep 20, 2006 8:35 am ] |
Post subject: | |
zylum wrote: what exactly are you making that needs to that fast? I'm planning on making a 2d version of Battlefield 2. |
Author: | bugzpodder [ Wed Sep 20, 2006 9:14 am ] |
Post subject: | |
or look into python C API. although its more for C++ programmers to have access to python, rather than other way around |
Author: | wtd [ Wed Sep 20, 2006 10:45 am ] |
Post subject: | |
I would mention that Ruby is considered to have one of the simplest C interfaces available. With it you can wrap C code so that it can be called from Ruby just as you would call any other Ruby code. |
Author: | do_pete [ Wed Sep 20, 2006 11:26 am ] |
Post subject: | |
Yes but we're doing Python for grade 11 programming so I'm stuck with it. |
Author: | [Gandalf] [ Wed Sep 20, 2006 3:17 pm ] |
Post subject: | |
Stuck? Hardly... I'd say it's better than most of the alternatives that would have been chosen. Just thought I'd add that in. |
Author: | neufelni [ Wed Sep 20, 2006 4:07 pm ] |
Post subject: | |
I agree. Python is a great language. I'd much rather learn Python in school than Turing. |
Author: | wtd [ Wed Sep 20, 2006 4:19 pm ] |
Post subject: | |
do_pete wrote: we're doing Python for grade 11 programming
Which version? Oh, and don't be concerned with how fast your programs run. Much more important is to learn to write and understand idiomatic Python code. |
Author: | bugzpodder [ Wed Sep 20, 2006 7:50 pm ] |
Post subject: | |
wtd has on several occasions mentioned its drawbacks, but in most respects turing is a fairly good language to introduce to someone who is new to programming, esp given its structural resemblence to C++. |
Author: | wtd [ Wed Sep 20, 2006 10:49 pm ] |
Post subject: | |
bugzpodder wrote: wtd has on several occasions mentioned its drawbacks, but in most respects turing is a fairly good language to introduce to someone who is new to programming, esp given its structural resemblence to C++.
Ignoring all other aspects of this, Turing has very little semantic or syntactic resemblance to C++. Perhaps to C, but even then, not so much. A closer match in terms of semantics would be Pascal, which due to the availability of free tools and its historically widespread use in education is still likely a better pedagogical language. |
Author: | do_pete [ Thu Sep 21, 2006 9:21 am ] |
Post subject: | |
bugzpodder wrote: wtd has on several occasions mentioned its drawbacks, but in most respects turing is a fairly good language to introduce to someone who is new to programming, esp given its structural resemblence to C++. I think he means Python, not Turing. We are using the most recent version of Python, 2.4.3. |
Author: | Cervantes [ Thu Sep 21, 2006 9:39 am ] |
Post subject: | |
do_pete wrote: We are using the most recent version of Python, 2.4.3.
Python 2.5 was released on Tuesday. link! But we can't expect your school to keep up with that, I guess. It's impressive enough that you're learning Python in class. I envy you. |
Author: | do_pete [ Thu Sep 21, 2006 9:52 am ] |
Post subject: | |
I didn't know that, I thought that it was still just a release canditate. |
Author: | bugzpodder [ Thu Sep 21, 2006 7:53 pm ] |
Post subject: | |
wtd wrote: bugzpodder wrote: wtd has on several occasions mentioned its drawbacks, but in most respects turing is a fairly good language to introduce to someone who is new to programming, esp given its structural resemblence to C++.
Ignoring all other aspects of this, Turing has very little semantic or syntactic resemblance to C++. Perhaps to C, but even then, not so much. A closer match in terms of semantics would be Pascal, which due to the availability of free tools and its historically widespread use in education is still likely a better pedagogical language. i thought C and C++ are almost identical minus OO stuff. I recall a large comparison chart as an effort for Holtsoft to promote turing in an effort to show similarities between turing and pascal. I think it is a fairly smooth transition from Turing to C++. In fact that was the path I went down. It wasn't that long ago. |
Author: | wtd [ Thu Sep 21, 2006 11:00 pm ] |
Post subject: | |
bugzpodder wrote: i thought C and C++ are almost identical minus OO stuff.
The object-oriented stuff is a fairly significant difference, but there are namespaces, templates, function/operator overloading... C++ is best viewed as an entirely different language that happens to maintain a fairly high level of compatibility with C. Objective-C is a perfect superset of C that adds support for object-oriented programming. |