World: r3wp
[Core] Discuss core issues
older newer | first last |
Terry 16-May-2010 [16620x2] | or decimals? |
I'm looking for a delmiter in hash keys to separate two integers that i can perform a select/any on | |
Gregg 17-May-2010 [16622x2] | I've never tried, but I imagine you would have to form them for /any to work. |
It should be easy to test though. | |
Terry 17-May-2010 [16624] | How about this one.. Determine the first decimal place of decimal dec: 209.648 and I want to return the 6 |
Graham 17-May-2010 [16625] | to-integer multiply dec - to-integer dec 10 |
Terry 17-May-2010 [16626] | hmm, smart |
Sunanda 17-May-2010 [16627] | Or using strings: to-integer form first next find form dec "." == 6 |
Graham 17-May-2010 [16628] | interesting to benchmark but I suggested a math solution as normally math is faster than anything else |
Terry 17-May-2010 [16629] | ok, one last one for my rusty rebol FINDing the index of all occurences of an integer in a series ie: blk: [ 239 4545 23 655 23 656[ search for 23 and return [3 5] (not using foreach) |
Graham 17-May-2010 [16630] | use parse |
Terry 17-May-2010 [16631x3] | first one is result: find blk 23 .. but how to quickly find the rest foreach is way too slow on blocks with large amounts of data |
err: index? find blk 23 | |
and my gut says parse is worse than foreach, no? | |
Graham 17-May-2010 [16634] | what's your gut got to do with it? |
Ladislav 17-May-2010 [16635] | hmm, interesting, I am quite curious, which approach would be the fastest one |
Terry 17-May-2010 [16636] | FIND, SELECT and PICK are blazing.. foreach is a game killer. Need to work out a way to FIND all values |
Pekr 17-May-2010 [16637] | Hmm, too long :-) to-integer to-string first second parse to-string 123.456 "." |
Sunanda 17-May-2010 [16638] | You could tweak something like this: res: make block length? blk while [ind: find blk 23] [print blk append res index? ind blk: skip blk last res] blk: head blk probe res But remember the first rule of REBOL Code Golf: parse always wins.....We're now just waiting for a parse guru to show us how :) |
Graham 17-May-2010 [16639] | Ladislav is working on it now :) |
Terry 17-May-2010 [16640] | This is the last piece to my Redis killer |
Pekr 17-May-2010 [16641x2] | parse blk [some [s: set value integer! (if value = 23 [print index? s])]] |
not sure my version will be the smartest solution, but you can try how fast it is :-) | |
Ladislav 17-May-2010 [16643x2] | indices?-1: func [ series [series!] value /local result ] [ result: make series 0 while [series: find series value] [ append result index? series series: next series ] result ] indices?-2: func [ series [series!] value /local result ] [ result: make series 0 parse series [ any [1 1 value series: (append result subtract index? series 1) | skip] ] result ] >> time-block [indices?-1 blk 23] 0,05 == 0.000006591796875 >> time-block [indices?-2 blk 23] 0,05 == 0.000005645751953125 |
(in R3) | |
Pekr 17-May-2010 [16645] | Could you rewrite my example as indices-3? :-) |
Terry 17-May-2010 [16646] | How about Rebol 2 version? |
Graham 17-May-2010 [16647x2] | pekr, your example will be slower |
since your comparison is occuring in a mezzainine | |
Pekr 17-May-2010 [16649] | what mezzanine? |
Terry 17-May-2010 [16650] | Lad, it works in R2 as well. |
Graham 17-May-2010 [16651x2] | if value = 23 |
but Ladislav is doing this 1 1 23 | |
Ladislav 17-May-2010 [16653] | yes, that (in R3) means, that the times obtained are in R3 |
Pekr 17-May-2010 [16654x2] | where do I get time-block from for R3? |
where do I get time-block from for R3? | |
Ladislav 17-May-2010 [16656x2] | Write: do http://www.fm.tul.cz/~ladislav/rebol/timblk.r |
hmm, what does this mean? Is it intended? In R3: >> exists? http://www.fm.tul.cz/~ladislav/rebol/timblk.r == none | |
Pekr 17-May-2010 [16658x2] | Hmm, my version is much slower: indices?-3: func [ series [block!] value [integer!] /local result ][ result: make series 0 parse series [ any [s: set wanted integer! (if value = wanted [append result index? s])] ] result ] >> time-block [indices?-1 blk 23] 0,05 == 0.000004669189453125 >> time-block [indices?-2 blk 23] 0,05 == 0.0000039520263671875 >> time-block [indices?-3 blk 23] 0,05 == 0.0000059661865234375 |
what is this dirty trick good for? :-) 1 1 value ??? | |
Graham 17-May-2010 [16660] | It's because you can't match an integer like a word |
Terry 17-May-2010 [16661x2] | looks like foreach is still the winner (on r2) |
Against a block with 100,000 integers Lad's : 0.047 foreach: 0.044 | |
Ladislav 17-May-2010 [16663] | Terry, you did not write the Foreach-base algo here, so nobody can compare... |
Graham 17-May-2010 [16664] | 1 1 value means to run the rule once and only once where value is the rule |
Pekr 17-May-2010 [16665] | A bit adapted Lad's version (does not use substraction): indices?-4: func [ series [series!] value /local result ] [ result: make series 0 parse series [ any [series: 1 1 value (append result index? series) | skip] ] result ] >> time-block [indices?-2 blk 23] 0,05 == 0.000003936767578125 >> time-block [indices?-4 blk 23] 0,05 == 0.000003753662109375 |
Ladislav 17-May-2010 [16666x2] | interesting, I thought, that this modification would be slower |
(index?-2 spares four assignments, while index?-4 spares two subtract calls) | |
Terry 17-May-2010 [16668x2] | what are your results compared to foreach? |
gotta go.. bedtime in the pacific northwest | |
older newer | first last |