From: C.DeRykus on 17 Mar 2010 09:05 On Mar 17, 3:00 am, Oliver 'ojo' Bedford <news...(a)web.de> wrote: > Am Mon, 15 Mar 2010 16:00:42 +0000 schrieb bugbear: > > > Jürgen Exner wrote: > >> Oliver 'ojo' Bedford <news...(a)web.de> wrote: > >>> For testing purposes I would like to fill chunks of memory (say 20M) > >>> with arbitrary data (say bytes with values 1,2,...255,1,...). > > >>> What would be the fastest method? > > >> The easiest method would probably be to define a string with say 256 > >> bytes and then use the x operator to repeat it. I would guess it would > >> also be quite fast because it uses perl interna only and doesn't > >> involve a user-level loop. > > > If speed is really important (it often isn't) you may be able to > > repeatedly "double up" by copying the head of the 20Meg space to itself.. > > Thanks for the help. I'll try both methods. > > Speed is not important in my case - it's just a matter of convenience > (and impatience on my side). > You may want to reconsider speed on Win32 though if you've seen the recent thread "Help on string to array": http://groups.google.com/group/comp.lang.perl.misc/browse_thread/thread/ddc58df14fe6e965/9c713aab4e254fdf?hl=en&lnk=gst&q=malloc+Win32# One speed-up possibility is to grow the string by doubling: $max = 20_000_000; $str = pack "C*",0..255; do {$str .= $str;} until length $str >= $max; substr($str, $max-length($str)) = ''); -- Charles DeRykus
From: ccc31807 on 17 Mar 2010 10:00 On Mar 15, 5:22 am, Oliver 'ojo' Bedford <news...(a)web.de> wrote: > Hi! > > For testing purposes I would like to fill chunks of memory (say 20M) with > arbitrary data (say bytes with values 1,2,...255,1,...). > > What would be the fastest method? > > Oliver Use the recursive Fibonacci function, not tail recursive. It calls itself twice on each iteration, so clogs up memory even for small values. use strict; use warnings; sub fib { my $n = shift; if ($n <= 1) { return 1; } else { return (fib($n - 1) + fib($n - 2)); } } my $N = $ARGV[0]; my $f = fib($N); print "$f\n"; exit(0);
From: Ted Zlatanov on 17 Mar 2010 14:47 On Wed, 17 Mar 2010 07:00:13 -0700 (PDT) ccc31807 <cartercc(a)gmail.com> wrote: c> On Mar 15, 5:22�am, Oliver 'ojo' Bedford <news...(a)web.de> wrote: >> For testing purposes I would like to fill chunks of memory (say 20M) with >> arbitrary data (say bytes with values 1,2,...255,1,...). >> >> What would be the fastest method? c> Use the recursive Fibonacci function, not tail recursive. It calls c> itself twice on each iteration, so clogs up memory even for small c> values. Out of curiousity, did you come up with this method for filling memory on your own? I haven't seen it in the literature. It could be patentable. Ted
From: ccc31807 on 17 Mar 2010 16:29 On Mar 17, 2:47 pm, Ted Zlatanov <t...(a)lifelogs.com> wrote: > Out of curiousity, did you come up with this method for filling memory > on your own? I haven't seen it in the literature. It could be > patentable. > > Ted This is the standard recursive definition of Fibonacci, and I can't take the credit for it. In Joe Armstrong's book on Erlang, he gives a multi threaded way of filling memory using threads, which is very easy and interesting. CC.
First
|
Prev
|
Pages: 1 2 Prev: FAQ 7.8 How do I declare/create a structure? Next: check for file in $PATH |