String() Vs DAT
Ray0665
Posts: 231
I have been using DAT statements for all my strings rather than the inline string() statement for some time now. And tonight with some idle time on my hands I was wondering if using the DAT statement had any advantage over the inline. My gut was saying yes but then there is this matter of hub ram access so I just wasn't sure. Only one way to find out.... Two identical loops so the only difference is string() vs DAT
test it... Now I know for sure.
test it... Now I know for sure.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 count = 10000 obj pst: "Parallax serial Terminal" dat msg byte "text",0 pub main| t,t1,t2,s pst.start(115200) repeat 50 pst.str(string(13,"first ")) t := cnt repeat count ' s := string("text") s := @msg t1 := cnt - t pst.dec(t1) pst.str(string(" second ")) t := cnt repeat count s := string("text") ' s := @msg t2 := cnt - t pst.dec(t2) pst.str(string(13,"Avg Difference (in clock cycles):")) pst.dec((t2-t1)/count) pst.newline
Comments
Normally I would defer to what you say because of all the good advice you have given, however in this case I have the program as evidence and it shows a difference of 16 clocks between the two. I did two repeat loops with nothing but the assignment of the strings address to a variable in the loop and recorded the elapsed time in clocks of the loop. One used DAT the other STRING(). The conclusion is that dat is faster than String. If I missed something here please point it out so that I may learn from it.
I was just curious and had nothing to do. So now we know all about different encoding methods and the inner workings of the compiler - good stuff.
As Mike said 16 clocks is insignificant in light of other wasted cycles in any practical application.
And I thank you for the great info.