[Gambas-user] (To Benoit) - About SHELL slowlyness
Benoît Minisini
gambas at ...1...
Sat Feb 7 00:14:21 CET 2009
> I tried to investigate whether is true that SHELL is slow.
>
> I searched for a directory having a few short file, and tried with
> /usr/share/services (188 files and some directory).
>
> Then I typed:
> time for a in *; do sh -c "cp $a /tmp"; done
> cp: directory `kaddressbook' omessa <-- "omessa" = "omitted"
> cp: directory `kded' omessa
> cp: directory `kontact' omessa
> cp: directory `kresources' omessa
> cp: directory `searchproviders' omessa
> cp: directory `useragentstrings' omessa
>
> real 0m1.784s
> user 0m0.768s
> sys 0m0.912s
>
> -------------------------
> Then I did:
> time for a in /tmp/*; do sh -c "rm $a"; done
> rm: impossibile rimuovere `/tmp/gambas.0': Is a directory
> rm: impossibile rimuovere `/tmp/kde-root': Is a directory
> rm: impossibile rimuovere `/tmp/ksocket-root': Is a directory
> rm: impossibile rimuovere `/tmp/ssh-DtpWml2479': Is a directory
>
> real 0m1.425s
> user 0m0.632s
> sys 0m0.756s
> ----------------------------
>
> Then I tried to do the same thing inside the gambas app. The code for
> the copy operation is as follows:
>
> initime = Timer()
> FOR EACH fname IN fvMain.Selection
> mess("Copying '" & fname & "'...") ' <<<--- sets a label and
> issues a WAIT to update the screen
>
> IF Exist(fvAux.dir &/ fname) THEN
> reply = Message.Question("\"" & fname & "\" already exist.
> Overwrite?", "&No", "&Yes", "&Stop!")
> IF reply = 1 THEN CONTINUE
> IF reply = 3 THEN
> status("Interrupted: only copied " & cnt & " files.")
> RETURN
> ENDIF
> ENDIF
>
> SHELL "cp -r \"" & fvMain.Dir &/ fname & "\" \"" & fvAux.Dir & "\"
> 2>&1" TO res
> IF res <> "" THEN
> reply = Message.error("Copying, shell replied: " & res, "&Stop",
> "Go on")
> IF reply = 1 THEN
> mess("Interrupted: only copied " & cnt & " files.")
> BREAK
> ENDIF
> ELSE
> INC cnt
> ENDIF
> NEXT
>
> status("Copied " & cnt & " files. " & (Timer() - initime) & "secs.")
> fvAux.Reload
>
> This routine took 3.133 seconds (after selecting the 188 files in
> /usr/share/services and issued a copy to /tmp).
> -------------------------------------------
>
> Then I tried the delete operation. The code is the following one:
>
> initime = Timer()
> FOR EACH name IN lastfv.Selection
> fname = lastfv.Dir & "/" & name
> IF IsDir(fname) THEN
> IF askdirs THEN
> reply = Message.Question("About to delete a directory. Sure to
> delete " & fname & "?", "&Yes", "Yes to &All", "&No")
> IF reply = 3 THEN RETURN
> IF reply = 2 THEN askdirs = FALSE
> ENDIF
> SHELL "rm -r \"" & fname & "\" 2>&1" TO name
> IF name <> "" THEN
> Message.Info(name)
> ELSE
> dvMain.deldir(fname)
> ENDIF
> ELSE
> SHELL "rm \"" & fname & "\" 2>&1" TO name
> IF name <> "" THEN Message.Info(name)
> ENDIF
> NEXT
> mess("Took " & (Timer() - initime) & "seconds.")
>
> This routine took 1.86 seconds for 188 files (no directories selected)
> in /tmp.
>
> To summarize:
> copy operation on 188 short files (mostly 1K):
> bash: 1.78 seconds; gambas: 3.13 seconds
> ...the gambas code has the burden of updating a user message (a
> label); my graphic card is a slow one
>
> remove operation on 188 files:
> bash: 1.42 seconds; gambas: 1.86
> ...in this case, there is no burden - only the minimal necessary
> things are done
>
> File system type is ext2 for both / (where /tmp resides) and /usr
> (mounted on /).
> My machine is a Duron 900 with 256K ram (yes, I know, a monster
> machine!), running Debian stable and an ATI Radeon as video card.
>
> Now some consideration.
> When opening my /home/mp3 directory, which contains 702 items (songs),
> gambas is far faster than KDE. The routine is basically a slightly
> modified version of FileView - but it does nearly the same things: open
> dir, stat() (two times!) every file, raise event to get icon, add the
> filename to a ListView. My conclusion is that the interpreted bytecode
> is fast - at least faster than bash interpreting a "for" cycle. So the
> slowlyness should not belong to bytecode.
>
> When copying 188 files, the gambas code does three things:
> 1. Update a label to let the user know what file is under copy
> 2. Test for the destination existance
> 3. SHELL to "cp file ..."
>
> Apart from the label stuff, all the things are also done by the bash
> command line. But the time for gambas is double. One could assume this
> is because the label stuff (assuming that bytecode interpretation is
> faster than bash interpretation - but I think this is easily and
> certainly true).
>
> When deleting 188 files, gambas is marginally slower than bash. But this
> time there is no burden about labels; the gambas code does almost the
> same things bash does, but is still slower. I point my attention to the
> SHELL instruction, but I could be wrong.
>
> Benoit, you are right when you say "there is no reason why SHELL should
> be slow",
I didn't say that. I was talking about the EXEC instruction. The SHELL
instruction runs a program inside /bin/sh, whereas EXEC runs it directly.
In other words,
SHELL "abcd"
<=> EXEC [ "/bin/sh", "-c", "abcd" ]
So it is logical that you find Gambas slower. You are actually comparing
Gambas + bash with bash alone!
Regards,
--
Benoît
More information about the User
mailing list