From: Bill Guindon Date: 2004-09-28T10:39:21+09:00 Subject: Re: {newb} Each statements On Tue, 28 Sep 2004 09:33:16 +0900, James Edward Gray II wrote: > ndata = ndata.split(//).map{ |c| ((c[0]-97)+rand(10))%26 }.join That started to look a bit too perl like for me, so I decided to compare the 'each_byte' and the 'split' approaches. Granted, it's a simple comparison, but seems each_byte is a bit faster, and looks easier to read (at least to me). btw, suggestions on simple benchmarking welcome. Here's my simple comparison script: ###################################### data = "some really silly string of text which will be encrypted soon" ###################################### def encrypt_byte(data) ndata = '' a = data.size-1 srand(5000) data.each_byte {|c| ndata << (((c-96)+rand(10))%26) + 97} return ndata end ###################################### def encrypt_split(data) ndata=data.dup a = ndata.size-1 srand(5000) ndata = ndata.split(//).map{ |c| (((c[0]-96)+rand(10))%26 + 97).chr}.join end ###################################### t0 = Time.now 1000.times do puts encrypt_byte(data) end t1 = Time.now 1000.times do puts encrypt_split(data) end t2 = Time.now puts t1 - t0, t2 - t1 -- Bill Guindon (aka aGorilla)