You know that if you want to use J and be fast you have to read in big
pieces every time you read from the file and best is to read it in one go if
it is small enough.
2007/9/23, William James <[EMAIL PROTECTED]>:
>
> At Mon Sep 24 01:01:12 HKT 2007, Joey K Tuttle wrote:
>
> > At 02:53 -0700 2007/09/23, William James wrote:
> > >Bjorn Helgason wrote:
> > >
> > >> 65 66 67{a.
> > >
> > >Thanks. I needed this to convert a simple program that
> > >was posted on the Ruby newsgroup to J.
> > >
> > >Here's a cleaned up Ruby version.
> > >
> > >def scramble( fname )
> > > _fname = fname + ".scrambled"
> > > data = IO.read( fname )
> > > File.open(_fname, "wb"){|ff|
> > > data.each_byte{|c| ff.write((c | 0x80).chr) }
> > > }
> > >end
> > >
> > >Here's my J version.
> > >
> > >read =: 1!:1
> > >write =: 1!:2
> > >scramble =: verb define
> > >((128 (23 b.) a. i. read <y) { a. ) write <y,'.scrambled'
> > >)
> > >
> > >The J program is about 24 times as fast.
> > >The version I wrote in FreeBasic is 9 times as fast as J.
> > >
> >
> > Interesting - what did your FreeBasic version look like?
>
> It's very verbose; the language is designed to be quite
> compatible with Microsoft's QBasic, although it has pointers and
> C-style macros. The executable is 27,648 bytes. (I hope we won't
> be tarred and feathered for being so off topic.)
>
>
> ' The comment character (') is almost invisible.
> sub scramble( filename as string )
> dim as integer in_handle, out_handle, i, size
> dim bytes(1 to 4096) as byte
>
> in_handle = freefile
> open filename for binary access read as in_handle
> out_handle = freefile
> open filename & ".scrambled" for binary access write as out_handle
> while not eof( in_handle )
> size = seek( in_handle )
> get #in_handle, , bytes()
> size = seek( in_handle ) - size
> for i = 1 to size
> bytes(i) = bytes(i) or &h80
> next
> put #out_handle, , bytes(1), size
> wend
> close '\ Caution. Closes all open files.
> end sub
>
> dim t as double
> t = timer
> scramble "words"
> print timer - t
>
>
>
>
>
> ____________________________________________________________________________________
> Be a better Globetrotter. Get better travel answers from someone who
> knows. Yahoo! Answers - Check it out.
> http://answers.yahoo.com/dir/?link=list&sid=396545469
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Björn Helgason, Verkfræðingur
Fugl&Fiskur ehf, Þerneyjarsund 23, Box 127
801 Grímsnes ,t-póst: [EMAIL PROTECTED]
Skype: gosiminn, gsm: +3546985532
Landslags og skrúðgarðagerð, gröfuþjónusta
http://groups.google.com/group/J-Programming
Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans
góður kennari getur stigið á tær án þess að glansinn fari af skónum
/|_ .-----------------------------------.
,' .\ / | Með léttri lund verður |
,--' _,' | Dagurinn í dag |
/ / | Enn betri en gærdagurinn |
( -. | `-----------------------------------'
| ) | (\_ _/)
(`-. '--.) (='.'=)
`. )----' (")_(")
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm