Here goes 0.0.6.. :)
With the help of Bearophile, I optimized list comprehensions and iteration a bit further. Programs are now also compiled together with the builtins, which can greatly improve performance in some cases. For example, the Pythonchess speed test engine now becomes about 22 times faster on my computer. Please check it out, and let me know about any problems you encounter.
For 0.0.7, I am working on a 'char' type. That is, let the compiler use the C++ 'char' type whenever programs are working with strings of length one. This dramatically improves the speed of programs that use strings of length 1 and/or 'string[index]' a lot. If you'd like to try it out, keep a watch on CVS, because I will commit this change soon, and let me know about any problems.
11 comments:
Hi,
how can I list file directory in Shed Skin? I got:
*ERROR* program:138: debug: no type!
Code starts to read and process files that begin with number 1-9, line 138 is "files=os.listdir('.')":
import os
files=os.listdir('.')
for file in files:
____if "1"<=file[:1]<="9":
________print file
________f=open(file, 'r')
...
I changed my code a little to get it to run:
- removed some code it doesn't support:
if os.path.exists(picpath + txt[4:].strip() + 'p.jpg')
- changed code:
txt = txt.rstrip()
=> txt.strip()
- isdigit() is not supported, so
if (txt.strip())[2:4].isdigit():
=> if "00"<=(txt.strip())[2:4]<="99":
Thanks for your work, I'll continue to study Shed Skin code.
Oh, and I got past the first problem files=os.listdir('.') by specifying filenames directly.
Hello xet7,
Thanks for your interest in Shed Skin. Yep, just a few library calls are implemented atm. You can see which these are, by looking at the *_.py files in the Shed Skin directory. You can easily add to these, by adding entries to these files, and supplying C++ versions in the corresponding *_.?pp files.
What kind of program are you trying to compile? Could you perhaps send it to the Shed Skin mailing list? (see http://shedskin.sourceforge.net)
The code just loads text file (line by line) that is in certain format, and formats it for inserting into database. Text file is originally from data input program made with VB.
That text file contains info about old photos: place, description, photographer, photo number etc. It then checks if that photo.jpg files exist on disk, and does name end with p (vertical) or v (horizontal).
It's only one-time-only used script, about 300 lines with comments, and there's not much use for that code without those photos and data text file. Of course if it was code that I'd use in more cases, then there would be more sense to modify it a little and make small data text file for example. I'll see if I have more time for that someday.
It doesn't sound like your program actually needs a speedup..? :) Anyway, does it work correctly now? Please let me know if you encounter any other problems, or you really need some library call.
Thanks!
Yeah, it doesn't need speedup :) but I had to start somewhere :)
C++/exe version works ok, produces the same numbers as the Python version. Result lines are in different order, but that doesn't matter, I'd like to to use Shed Skin with more important code than that.
Thanks for your friendly answers!
Btw, how difficult it would be to integrate SQLite (or wxWidgets) code to Shed Skin? So that Python version would work with pySQLite, and C++ version with C++ SQLite wrapper?
Right now, you need to provide a 'type model' of each used library function, as well as a C++ implementation. I guess, for SQLite and wxWidgets, you can call the C++ version from the C++ code.
Another possibility is to write the interface in Python (so you can use anything possible in Python), and put the cpu intensive parts in a separate program. For example, if you're writing a chess program, you can put the engine in a separate program, and communicate with it via a file.
So, is there a minimal example how to make interface in Python to that compiled C++ file? So that compiled program doesn't open separate window (like exec:ing it) but it's integrated like with SWIG or something? Does calling compiled code block the f.ex. wxPython GUI working, or can it run in separate thread (or something) and then notify wxPython GUI, or get some events / progress messages from compiled file?
hello xet,
sorry for the delayed response. mailing me is faster :) anyway, the compiled code becomes a binary, so you can use it like any other binary. that is, run it in the background, or start it and wait for it to finish (then you need to maintain some timer, probably, to update the UI now and then.)
hello xet7,
I just added os.listdir, str.rstrip, str.isdigit and some similar methods to CVS. I'll release them as part of SS 0.0.8 . please let me know if there are other methods you'd like me to add/implement. I'm not going to implement everything, but methods like os.listdir are quite useful and easily mapped to C++.
thanks,
mark.
Post a Comment