Wiki source for gtkdialogDocTips5


Show raw source

[[HomePage]] > [[SoftwareIndex|Software Index]] > [[SoftwareDevelopment|Development]] > [[gtkdialog|gtkdialog]] > [[gtkdialogDocTips|Tips and Tricks]]

====5. Speed issues====
Gtkdialog is not a fast gui-lib. If you are building a gui where speed matters, please check the following notes.

For an unknown reason, it is much faster to start your gtkdialog-xml-code from a file than from a variable.
##gtkdialog --file=filename
gtkdialog --program=variable##
The file alternative is highly recommended if your xml-code is getting complex.

Progressbars can suck your cpu-power. Adding a reasonable sleep value in the loop helps a lot.

Run large calculations as a background process. [[pMusic]] builtin filebrowser (version 0.9) first shows songs in the directory, then it starts a background process to find meta information of the songs. When finished, it renders the song-list once again, now with complete information. How to use a background process with gtkdialog is explained in the chapter '[[gtkdialogDocTips3 Let external code act on your gtkdialog gui]]'.

Even if gtkdialog is slow, your bash-code might make it MUCH slower. Be careful with the use of subshells, and slow commands such as ##sed, ps, expr, cat## ... This is of course most important when building a loop.

The comparison of code shows how to do the same operation in 2 different ways. The speed differs a lot. First an example why you should avoid the command ##cat##, then why never use ##expr## if speed matters. My system needed 4 seconds to calculate 1+1 thousand times with ##expr##. Using the builtin bash command it took 'no time'.

%%(language-ref)
time for I in $(seq 1 1000); do B="`cat /tmp/tmp`"; done
real 0m3.095s
time `IFS=$'\n'; for I in $(seq 1 1000); do B=($(<"/tmp/tmp")); done`
real 0m0.927s

time for I in $(seq 1 1000); do expr 1 + 1; done
real 0m4.286s
time for I in $(seq 1 1000); do A=$((1+1)); done
real 0m0.032s
%%

There are many ways of building a gui. The builtin file browser/filesearch in [[pBurn]] was updated from version 2 to [[pBurn]] 3. The code has shrunk from 3110 to 997 chars. It does exactly the same, and the speed improvement is notable.

===@@**#%[[gtkdialogDocTips4.2|❰❰❰ Previous]]#% #%[[gtkdialogDocTips|Index]]#% #%[[gtkdialogDocTips6.1|Next ❱❱❱]]#%**@@===
----
==Categories==
CategoryGtkdialog
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki