One theory I have is that , is optimized when ,~ is not. in tobase64, the second line does an optional append with , . When the length of the string is a multiple of 3, it appends 0#'=' (nothing). For length 100, it appends 2#'='
20 timespacex 'tobase64"1 ] 1000 100 $ a' 0.0250075 429824 20 timespacex 'tob64"1 ] 1000 100 $ a' 0.0196931 413824 20 timespacex 'tobase64"1 ] 1000 99 $ a' 0.0268403 429824 20 timespacex 'tob64"1 ] 1000 99 $ a' 0.0194453 413824 for the explicit version, it is strange that reading 100 chars per line and spitting out 2 extra takes less time than 99 chars per line with no extra output. the tacit version appends through ,~ , and shows the expected improvement of reading and appending less. ----- Original Message ----- From: Joe Bogner <[email protected]> To: [email protected] Cc: Sent: Wednesday, August 6, 2014 2:04:15 PM Subject: Re: [Jprogramming] unexpected explicit vs tacit benchmark My timings suggest that they are all about the same: 100 timespacex 'tob64 a' 0.0317417 1.78275e7 100 timespacex 'tobase64 a' 0.0316219 2.85809e7 100 timespacex 'tb64 a' 0.0313129 2.04608e7 Considering the explicit only has 2 lines, I'm not surprised the timings are about the same. I thought the biggest performance penalty from explicit is the parsing for each invocation. The parsing in this case is likely negligible since the explicit function isn't being called in a loop. On Wed, Aug 6, 2014 at 1:52 PM, Raul Miller <[email protected]> wrote: > You might try timings on sub-expressions to find where the speed > differences occur? > > Thanks, > > -- > Raul > > > On Wed, Aug 6, 2014 at 1:27 PM, 'Pascal Jasmin' via Programming > <[email protected]> wrote: >> BASE64=: (a.{~ ,(a.i.'Aa') +/i.26),'0123456789+/' >> >> tobase64=: 3 : 0 >> res=. BASE64 {~ #. _6 [\ , (8#2) #: a. i. y >> res, (0 2 1 i. 3 | # y) # '=' >> ) >> >> tob64 =: ('=' #~ 0 2 1 i. 3 | # ) ,~ BASE64 {~ [: #. _6 ]\ (8#2) >> ,@:#: a.&i. >> tb64 =: 3 : '(''='' #~ 0 2 1 i. 3 | # y) ,~ BASE64 {~ #. _6 ]\ (8#2) >> ,@:#: a.&i. y' >> >> frombase64=: 3 : 0 >> pad=. _2 >. (y i. '=') - #y >> pad }. a. {~ #. _8 [\ , (6#2) #: BASE64 i. y >> ) >> fb64 =:a. {~ [: #. _8 [\ (6#2) ,@:#: BASE64&i. }.~ _2 >. # -~ i.&'=' >> >> tobase64 is original code from addon. It is explicit with a temporary >> variable. tb64 is also explicit but without the temp var. tob64 is a tacit >> version. >> >> a =. 100000 $ a. >> >> timespacex 'tob64 a' >> >> 0.0312112 1.78275e7 >> timespacex 'tobase64 a' >> 0.0277369 2.85809e7 >> timespacex 'tb64 a' >> 0.0289411 2.04608e7 >> >> all are impressively fast, but the 2 explicit functions are faster, and >> somehow the one with a temp variable is fastest. >> >> the tacit version does use less space, as well as the one line tacit entry. >> Its also faster for array item application >> >> >> timespacex 'tob64"1 ] 100 1000 $ a' >> 0.0154246 539264 >> timespacex 'tobase64"1 ] 100 1000 $ a' >> 0.016376 628736 >> >> Its also surprising though that applying the function to 100 smaller items >> is faster than the whole. >> >> >> Any insights on why this is happening? >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
