They say Ruby is slow...
-
Ruby is not an interpreted language inside SU?
So this must explain that ? -
@thomthom said:
Heck even simple addition operation is dead slow... what to do?
Hi ThomThom,
I am glad you posted this because i've often wondered how python and ruby compare speedwise, now i have been proven right, again!
Here are the same tests using Python on a machine with less than half the power of yours!!! AMD Athlon 64X2 Dual Core Processor 4800+ 2.50 GHz
2.00 GB RAM (but windows Vista consumes half of it!)>>> tests = ["t=time.time()\nfor x in xrange(1000000);\n 1.0\nprint time.time()-t", "t=time.time()\nfor x in xrange(1000000);\n 1.0+2.0\nprint time.time()-t", "t=time.time()\nfor x in xrange(1000000);\n 1.0+2.0+3.0\nprint time.time()-t", "t=time.time()\nfor x in xrange(1000000);\n 1.0+2.0+3.0+4.0\nprint time.time()-t", "t=time.time()\nfor x in xrange(1000000);\n 1.0+2.0+3.0+4.0+5.0\nprint time.time()-t",] >>> for test in tests; exec test 0.0980000495911 0.12700009346 0.128000020981 0.125999927521 0.12700009346
-
for the inquisitive...
> t=Time.now; 1000000.times { 1.0 }; puts Time.now - t 0.113408 nil > t=Time.now; 1000000.times { 1.0 + 2.0 }; puts Time.now - t 0.364167 nil > t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 }; puts Time.now - t 0.607299 nil > t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 }; puts Time.now - t 0.824763 nil > t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 + 5.0 }; puts Time.now - t 1.06076 nil
Run in Ruby Console (with 3 browsers and 2 other editors open... might slow it a bit, but shouldn't really)
Model Identifier: iMac7,1
Processor Name: Intel Core 2 Duo
Processor Speed: 2.8 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 4 MB
Memory: 4 GB
Bus Speed: 800 MHz -
@jessejames said:
Here are the same tests using Python on a machine with less than half the power of yours!!!
What is more interesting here is that adding more arithmetic operations doesn't appear to increase the processing time as it does in Ruby. You only see a minor difference in the first test - without any arithmetic operations.
Is it due to + being a method in ruby? (I don't know how that works in Python)
-
@driven said:
Run in Ruby Console (with 3 browsers and 2 other editors open... might slow it a bit, but shouldn't really)
Model Identifier: iMac7,1
Processor Name: Intel Core 2 Duo
Processor Speed: 2.8 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 4 MB
Memory: 4 GB
Bus Speed: 800 MHzThis also has me curious - why is the speed difference so big between out systems? Both has Inter Core 2 cores - I even got a faster one, but yet... ?
-
@jessejames said:
It is really a disservice to all of us that Python is not included in SketchUp. Some will argue...
@unknownuser said:Well the dev team does not have time to support another language
Thats true, just give us the hooks we need and we will write and maintain the Python API and Python API docs, no need to lift a finger!Good News for Jesse ! It's already been DONE. It's called SuPy, and the current version is 1.6, written by a guy named Greg Ewing in New Zealand. Here's the link:
http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/Since YOU are our resident expert in Python... we appoint you to test it out and give us a report:
(1) Is it faster? (ie: SU Ruby scripts vs SU Python scripts)
(2) And can SU Python scripts be compiled?Anyone think of anymore evaluation questions?
-
@thomthom said:
@jessejames said:
Here are the same tests using Python on a machine with less than half the power of yours!!!
What is more interesting here is that adding more arithmetic operations doesn't appear to increase the processing time as it does in Ruby. You only see a minor difference in the first test - without any arithmetic operations.
Is it due to + being a method in ruby? (I don't know how that works in Python)
I'm not sure how the internals of Python and Ruby compare but i do know that Python is far superior to Ruby in many ways.
Some of which are learnability, rich documentation (both packaged and 3rd party), amazing introspection abilities, forced indentation (which promotes code readability), syntactic consistency (no Tim Toady), a huge stdlib which includes a built in GUI kit, multi-paradigm object oriented, imperative, and functional (without the perl symbols), very small number of key words (AND the best words where choosen), and of course much faster than Ruby, ...need i say more?
Actually there exist no better scripting language than Python. Python was built to be a powerful "pseudo code like syntax" programming language that non-programmers can learn very quickly whilst also never disappointing a professional.
It is really a disservice to all of us that Python is not included in SketchUp. Some will argue...
@unknownuser said:
Well the dev team does not have time to support another language
Thats true, just give us the hooks we need and we will write and maintain the Python API and Python API docs, no need to lift a finger!
And thats how the Ruby API should be handled too. This would take a major burden off the dev team and result in a much better interface for all of us. It will happen if all you scripters start beating the war drums, instead of just whining that Google doesn't make this or that method. We can make Ruby API exactly how we want to, and who else knows better what WE need?
Here is a short example of Python introspection and the wonderful help function.
>>> a = [1,2,3, 1,2,3] >>> type(a) <type 'list'> >>> dir(a) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> help(a.count) Help on built-in function count; count(...) L.count(value) -> integer -- return number of occurrences of value >>> a.count(1) 2
Now what if i want to see my namespace, easy!
>>> dir() ['__builtins__', '__doc__', '__name__', '__package__', 'a']
You can even write your own docstrings for functions, methods, and classes
>>> def add(x, y); " add(1,2) -> 3" return x+y >>> add.__doc__ ' add(1,2) -> 3' >>> help(add) Help on function add in module __main__; add(x, y) add(1,2) -> 3 >>> add(3,4) 7
It's the same for classes.
-
None the less. We're stuck with Ruby.
I am looking at C extensions now for my number crunching. -
@dan rathbun said:
@jessejames said:
It is really a disservice to all of us that Python is not included in SketchUp. Some will argue...
@unknownuser said:Well the dev team does not have time to support another language
Thats true, just give us the hooks we need and we will write and maintain the Python API and Python API docs, no need to lift a finger!Good News for Jesse ! It's already been DONE. It's called SuPy, and the current version is 1.6, written by a guy named Greg Ewing in New Zealand. Here's the link:
http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/Since YOU are our resident expert in Python... we appoint you to test it out and give us a report:
(1) Is it faster? (ie: SU Ruby scripts vs SU Python scripts)
(2) And can SU Python scripts be compiled?Anyone think of anymore evaluation questions?
Hello Dan,
Yes i already knew about SuPy because my begging, nagging, and borderline stalking to everyone on planet earth including GvR himself help to bring attention to the Python community of Python's role in SketchUp. I am forever in the service of Greg Ewing for his wonderful work on this module.
However, this is a Ruby module and not a REAL Python API. Basically Python calls Ruby code, then Ruby calls SketchUp, very inefficient! Therefore it suffers from extreme slow speeds and has to work around the differences between Python and Ruby languages. The intention of this module was to shed light on Python's abilities in the hope Google would then give us the hooks we need for a REAL Python API. I would love for all scripters to have a choice between Python and Ruby, and constantly improve both API's. This would foster even better plugins in the future, sadly though so many of the Ruby guys are so rabidly against it none of the noobs are brave enough to try it.
-
@jessejames said:
However, this is a Ruby module and not a REAL Python API. Basically Python calls Ruby code, then Ruby calls SketchUp, very inefficient!
That SUCKS! dang.. thot I was onto something.
-
@dan rathbun said:
@jessejames said:
However, this is a Ruby module and not a REAL Python API. Basically Python calls Ruby code, then Ruby calls SketchUp, very inefficient!
That SUCKS! dang.. thot I was onto something.
Well don't give up so easy Dan. I know you to be quite versed in the Ruby language and i think you may also be an accomplished C programmer. Maybe you could offer you expertise to the project? Are you interested?
...just don't blame me if you fall in love with the Python language and lament the shortcomings of all others
PS: i remember a while back you wanting to get wxRuby into the API as a usable GUI kit. I also believe strongly in the power of GUI kits over those atrocious web dialogs. With Python's built in GUI you need look no further!
-
@jessejames said:
Well don't give up so easy Dan. I know you to be quite versed in the Ruby language and i think you may also be an accomplished C programmer. Maybe you could offer you expertise to the project? Are you interested?
Perhaps... my list of to-dos is getting longer and longer. C was one of those languages I had to learn (and like Assembly,) have forgotten more than I remember. I can read it and understand what's happening, but I'd really have to reread the old textbook and play around to get comfy again. Some little Ruby extentions might do the trick.@jessejames said:
...just don't blame me if you fall in love with the Python language and lament the shortcomings of all others
Well, there are some things I don't like off the bat with Python. Those hanging indents with no block closures. I was really into Pascal for many years and don't mind the "end" keywords. With the editors we have now, it's nice to have the indent markers that line up the 'begin' and 'end'; I've gotten to rely on those. In Python... wait let me load one of the .py files from SuPy...Ok I see how they will work for Python... a bit strange, but the fold margin gives more info as to where blocks begin and end (at least in notepad++.) I had planned to learn Python for other things, even before I found Sketchup and Ruby.@jessejames said:
PS: i remember a while back you wanting to get wxRuby into the API as a usable GUI kit. I also believe strongly in the power of GUI kits over those atrocious web dialogs. With Python's built in GUI you need look no further!
Yes, but is it cross-platform, as WxRuby/WxWidgets claims to be? GTK+ or Fx or something else? -
And another thread gets hijacked off into dreamy python land...
-
Back on Subject [for a minute] XP(Pro) on Mac/Parallel
1000000.times { 1.0 + 2.0 + 3.0 }; puts Time.now - t t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 }; puts Time.now - t t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 + 5.0 }; puts Time.now - t 0.109 0.469 0.766 1.125 1.422 nil t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 + 5.0 }; puts Time.now - t 1.407 nil t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 }; puts Time.now - t 1.109 nil t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 }; puts Time.now - t 0.765 nil t=Time.now; 1000000.times { 1.0 + 2.0 }; puts Time.now - t 0.453 nil t=Time.now; 1000000.times { 1.0 }; puts Time.now - t 0.109 nil
pasted as a one by mistake, slows it a little...
Now, back off subject.
I posted about suPy.rb before, with very little response,
I've got hypocycloid.py and suPy.rb but I can't get them to run on the Mac, want to take a look?
john -
@driven said:
0.109
0.469
0.766
1.125
1.422Python is still quite a bit quicker. Thanks for posting these specs.
@unknownuser said:
I posted about suPy.rb before, with very little response,
I've got hypocycloid.py and suPy.rb but I can't get them to run on the Mac, want to take a look?I am very sorry i never saw the post. Only a few people have shown interest in SuPy from it's conception, probably due to the bulling from some higher ups in this group when Greg and I tried to announce it. But i will keep on despite the resistance because i know the language has much to offer for the noob programmer. And it would be a good motivator if people showed interest. I still have much docs to write and tutorials which never were completed.
From now on if anyone has questions about SuPy or Python feel free to contact me personally via PM. I will go out of my way to help you no matter what your level of programming skills are. I also help a lot with Ruby, it's just i am more versed in the Python language.
John, I don't have a Mac but i'll do everything in my power to get you up and running. Send me a PM immediately and let me see what i can do. The Good news is Greg is a mac fan so i know he built a solid mac version, or will update it if needed.
-
@dan rathbun said:
@jessejames said:
...just don't blame me if you fall in love with the Python language and lament the shortcomings of all others
Well, there are some things I don't like off the bat with Python. Those hanging indents with no block closures.Once you read code with no redundant end statements you'll wonder how you ever liked them in the first place. The forced indention of Python uses the visual aid of INDENT/DEDENT to mark blocks which the human eye notices much quicker than end or "}" or whatever. Let C hackers "eyeball-parse" brackets like a compiler until they go blind, let humans "read" code naturally!
@unknownuser said:
I had planned to learn Python for other things, even before I found Sketchup and Ruby.
Dan, i will personally give you (or anybody) a crash coarse in the Python language anytime you are ready send me a PM. I will show you everything i know, and i guarantee it won't be a waste of your time, you're going to like this language friend!
@unknownuser said:
@jessejames said:
PS: i remember a while back you wanting to get wxRuby into the API as a usable GUI kit.
Yes, but is it cross-platform, as WxRuby/WxWidgets claims to be? GTK+ or Fx or something else?Absolutely, even more so than wx. I don't know if you have messed around with wx but it is not as cross platform as they claim it to be. Yes it is a good full featured GUI kit but totally cross platform, no way!
@chris fullmer said:
And another thread gets hijacked off into dreamy python land...
Oh Chris, stop being theatrical!
-
@driven said:
I've got hypocycloid.py and suPy.rb but I can't get them to run on the Mac, want to take a look?
I DID download hypocycloid.py John, and looked at the links, viewed some of those videos, the author made at YouTube of his reducer drives. Amazing thing! Didn't know there was such a thing. I have some drive designs that could benefit from a 0 backlash mechanism, but they are not reduction, they would be a 1:3 step-up drive.
Anyhow... most of what I saw was math, not hard to translate to Ruby. The other thing is the calls to DXF would be tranlated to SU geometry calls, and then you'd use the built-in DXF exporter. Also his py file makes a flat profile, which would need to be pushpull'ed up to a given thickness.
I noticed... the DXF example at that guy's website had some of the lobes flawed when I loaded it into AutoCAD.
Anyhow.. have not had time to seriously consider a translation. -
@thomthom said:
...and I believed that. It is after all a scripting language we're talking about. But wow! - it's slow!
> > t=Time.now; 1000000.times { 1.0 }; puts Time.now - t > 0.1 > nil > > > t=Time.now; 1000000.times { 1.0 + 2.0 }; puts Time.now - t > 0.985 > nil > > > t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 }; puts Time.now - t > 1.85 > nil > > > t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 }; puts Time.now - t > 2.76 > nil > > > t=Time.now; 1000000.times { 1.0 + 2.0 + 3.0 + 4.0 + 5.0 }; puts Time.now - t > 3.685 > nil >
If I remember correctly, compilers started adding constant folding in the '80s. This is truly brain dead.
On the other hand, Ruby allows
1_000_000.times ...
when counting zeros gets annoying. A peculiar mixture of great stuff and trash. -
@martinrinehart said:
If I remember correctly, compilers started adding constant folding in the '80s. This is truly brain dead.
Just FYI. Strength Reduction is the transformation that would turn these loops into do_nothing loops. I remember in the late 80's being so impressed with gcc when it would simply remove
for (i=0; i<1000; i++);
because it has no side-effect. -
@adamb said:
Strength Reduction is the transformation that would turn these loops into do_nothing loops.
Yes, but that's for really sharp compilers. I was just expecting
func( 1.0 + 2.0 )
to be turned intofunc( 3.0 )
.
Advertisement