For Programmers: Free Programming Magazines  


Home > Archive > Tcl > June 2007 > Which is faster?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Which is faster?
john_hughes@mentor.com

2007-06-05, 7:10 pm

Ok, I am looking at some code and trying to figure out which is
faster. We have a lot of legacy code
to where some C/C++ code talks to tcl like this:


string argStr;
for ( )
{
argStr = "part {" + partNumber + "}";

Tcl_AppendResult(interp, argStr.c_str(), NULL);
}

return TCL_OK;



We have newer code that looks like this:

Tcl_Obj* listPtr = Tcl_NewListObj( 0, NULL );
string argStr;
for ( )
{
argStr = "part {" + partNumber + "}";


Tcl_ListObjAppendElement( interp, listPtr,
Tcl_NewStringObj( argStr.c_str(), -1) );
}

Tcl_SetObjResult( interp, listPtr );
return TCL_OK;



It seems that the first example is pre 8.0 code and the 2nd example is
for 8.0
and later. And the 8.0 example is the preferred method, correct? And
theoretically
more efficient and such because of less type conversions, etc.

I my specific case, the amount of "stuff" being done inside the for
loop is immense, so I was
wondering if the 2nd example is less efficient (time wise) than the
old style code. Mainly due
to the number of calls to Tcl_NewStringObj() and
Tcl_ListObjAppendElement(). I know I can
profile the code to figure this out, but I thought you guys might save
me some time.

Thanks,

John

Ralf Fassel

2007-06-06, 7:22 pm

* john_hughes@mentor.com
| I my specific case, the amount of "stuff" being done inside the for
| loop is immense, so I was wondering if the 2nd example is less
| efficient (time wise) than the old style code. Mainly due to the
| number of calls to Tcl_NewStringObj() and
| Tcl_ListObjAppendElement().

The difference is how you use the result. The first form builds the
result as a string. If you use this later as a list, TCL converts it
to a list then, which delays the processing work to that later time.

The second form builds a list right now. If you use this as a list
later, the work is already done.

Possible improvements:
- c++ strings know their length, so pass argStr.size() instead of -1
as length argument for Tcl_NewStringObj() - saves one call to strlen().


If the list elements themselves are used as (sub-)lists:
- instead of manually building sublists using the + "{"+ "}" approach,
use real sublists:

Tcl_Obj *part = Tcl_NewStringObj("part", 4);
for () {
Tcl_Obj *sublist = Tcl_NewListObj( 1, &part );
Tcl_ListObjAppendElement(interp, sublist, Tcl_NewIntObj(partNumber));
Tcl_ListObjAppendElement( interp, listPtr, sublist);
}
Tcl_SetObjResult( interp, listPtr );

Note that I assume that the "{" "}" stuff is some manual
list-conversion left over from old-style TCL. If you really need the
"{}" in the data, you should keep the StringObj approach.

As always, error checking might be a good idea, too.

HTH
R'
Dertenster5

2007-06-08, 1:49 am

Pamela Anderson and Shania Twain Pussy Licking & Fighting!
http://www.shockingonline.com/Watch?id=1673286


movie of couple having sex big black cock sex free teen sex vids free celeb sex tape lesbian sex video clip
http://ztby1c4l.t35.com/anal-sex/an...e-hard-sex.html http://ss6cnhgd.t35.com/gay-sex-mov...-sex-movie.html http://yxss6yjt.t35.com/sex-video/h...-sex-video.html http://bfaqolfz.t35.com/black-sex/a...lack-woman.html http://yhqbl1u3.t35.com/world-sex/world-sex-site.html
Mopo

2007-06-09, 4:39 am

Lindsay Lohan and Tara Reid In The Countryside!
http://www.hiltonraped.com/Watch?movie=1673286

free amateur sex card consolidate consolidation credit debt debt loan asian sex pic celebrity sex video best sex movie
drawn sex com first time lesbian sex free homemade sex movie free live sex show card consolidation credit debt reductio
sex education for teen gay sex video kinky sex toy anal forum sex nude teen sex
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com