Getting file size [speed tests]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
miskox
Posts: 555
Joined: 28 Jun 2010 03:46

Getting file size [speed tests]

#1 Post by miskox » 30 May 2014 14:09

I am updating my program to maintain a database with 24000+ records. I changed it to INDEXED file (see viewtopic.php?f=3&t=5552). It works very well (I have 12 fields, demo has only 3 - one of the changes was splitting the first field (record offset+record length to two separate fields so I need less code)). I also made a reindex program and there I saw some speed problems.

I did two tests in speed of getting file size into a variable. Both solutions are here on DOSTIPS somewhere.
First uses FINDSTR, the second uses FOR with %~z.

The test code creates new file (with a new filename and new content to minimize the caching (probably). Gettimestamp.cmd is required. If your computer is too fast for 200 files then increase this number:

Code: Select all

@echo off
echo Version1: findstr
echo %time%
call getTimestamp -f {ums} -r t1
set /a cnt=0
:0
echo %cnt% THE QUICK BROWN FOX JUMPS OVER A LAZY DOG>%cnt%.tmp
echo.>>%cnt%.tmp
for /f "delims=:" %%i in ('findstr /o $ %cnt%.tmp') do set /a len=%%i
del %cnt%.tmp
set /a cnt+=1
if %cnt% LSS 200 goto :0
echo %time%
call getTimestamp -f {ums} -r t2
call getTimestamp -d %t2%-%t1% -f "{ud} days {hh}:{nn}:{ss}.{fff}" -u

echo(
echo --------------------------
echo(

echo Version2: FOR
echo %time%
call getTimestamp -f {ums} -r t1
set /a cnt=0
:1
echo %cnt% THE QUICK BROWN FOX JUMPS OVER A LAZY DOG>%cnt%.tmp
for %%Z in (%cnt%.tmp) do set len=%%~zZ
del %cnt%.tmp
set /a cnt+=1
if %cnt% LSS 200 goto :1
echo %time%
call getTimestamp -f {ums} -r t2
call getTimestamp -d %t2%-%t1% -f "{ud} days {hh}:{nn}:{ss}.{fff}" -u

echo(
echo END


The results:

Code: Select all

Version1: findstr
22:06:24,65
22:06:37,68
0 days 00:00:13.015

--------------------------

Version2: FOR
22:06:38,20
22:06:38,98
0 days 00:00:00.813

END


Maybe you Experts can get a faster version?

Saso

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Getting file size [speed tests]

#2 Post by Squashman » 30 May 2014 15:24

I can't imagine anything being faster then using the FOR Modifiers.

Post Reply