Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Performance improvement splitting huge file
#4
2GB file split in about 3 seconds on my drive.

Code: (Select All)
_DEFINE A-Z AS _INTEGER64
PRINT "Creating file data"
'create a nice large temp file
a$ = "Hello World. I'm Testing Crap!"
FOR i = 1 TO 26
a$ = a$ + a$
NEXT


OPEN "test.txt" FOR BINARY AS #1
PRINT "Writing file data", LEN(a$)
PUT #1, , a$
CLOSE

infile$ = "test.txt" 'the file to read in and split
savefile$ = "split test" 'the name of the files to save to, without extension or index
Splitfiles = 11 'split it into 11 parts (or whatever you want)


OPEN infile$ FOR BINARY AS #1
SplitFileSize = _CEIL(LOF(1) / Splitfiles)
PRINT "Splitting file data", SplitFileSize



t## = TIMER
i = 0: p = 1
DO UNTIL EOF(1) OR p > LOF(1)
i = i + 1
IF p + SplitFileSize > LOF(1) THEN SplitFileSize = LOF(1) - SplitFileSize * (i - 1)
partialfile$ = SPACE$(SplitFileSize)
GET #1, , partialfile$
p = p + SplitFileSize
outfile$ = savefile$ + "(" + _TRIM$(STR$(i)) + ").split"
PRINT "Writing file: "; outfile$, LEN(partialfile$)
OPEN outfile$ FOR OUTPUT AS #2: CLOSE #2
OPEN outfile$ FOR BINARY AS #2
PUT #2, , partialfile$
CLOSE #2
IF i > 100 THEN Explode
LOOP
PRINT USING "Done in ###.### seconds."; TIMER - t##

SUB Explode
BEEP
BEEP
BEEP
PRINT "OMG!! WE just filled the drive with a ton of crap from a bad, endless split!!"
BEEP
BEEP
BEEP
PRINT "HELP!!"
BEEP
BEEP
BEEP
PRINT "HELP!!"
BEEP
BEEP
BEEP
PRINT "DELETE IT ALL!! HEEEEEELLLPPPP!!!"
BEEP
BEEP
BEEP
END
END SUB
Reply


Messages In This Thread
RE: Performance improvement splitting huge file - by SMcNeill - 10-21-2023, 03:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  performance drop on LINUX with PSET in v4.2 Herve 12 972 11-20-2025, 02:00 PM
Last Post: SpriggsySpriggs
  for performance, what's the best variable type to use for boolean _TRUE & _FALSE ? madscijr 12 1,258 09-29-2025, 02:59 PM
Last Post: dakra137

Forum Jump:


Users browsing this thread: 1 Guest(s)