[REBOL] Re: Speed required
From: tim-johnsons:web at: 29-Nov-2007 11:04
On Thursday 29 November 2007, Kai Peters wrote:
> > Hi Kai:
> > I'm not sure if I fully understand your need, but if you are looking for
>
> column values 1, 2 & 5,
>
> > why not compose your SQL query to those specific columns in that order?
> > as
>
> in "select
>
> > col1,col2,col5 from MyTable"? If I've missed the boat here - sorry! Oh,
>
> and what do you mean by
>
> > 'transform'? regards tim
>
> Or - to hopefully make it even more clear:
>
> Here's what I have been using:
>
> cursor: [
> [ 100 "Kai" 49 #764-0929]
> [ 101 "Zu" 52 #764-0915]
> [ 102 "Dewi" 16 #312-1772]
> ]
> cols: [ 1 2 4 ]
Aha! 'cursor applies to the entire result set.
See comments below
> remove-columns: function [ cursor [block!] columns [block!]] [ tmp result
> ]= [
>
;; below could be a time penalty if function in a loop or nested loop
> result: copy []
> foreach record cursor [
;; below could be a time penalty if function in a loop or nested loop
> tmp: copy []
> foreach column columns [
> append tmp pick record column
> ]
> append/only result tmp
> ]
> result
> ]
>
> probe remove-columns cursor cols
I'd recommend that you
1)try to make a reasonable assumption about amount of memory usage,
2)double that amount :-)
3)create your 'result and 'tmp blocks before iteration starts using 'make
instead of 'copy to reserve memory and hopefully prevent resizing - which
would be something like a 'realloc() call in the native code
4)pass them as arguments to 'remove-columns
'clear'ing them first....
I don't do a lot of processing of big record sets with rebol, but
I would guess that memory allocation and reallocation would
be an issue.
I hope this adds to what Gregg has provided.
Tim