Jump to content
Sign in to follow this  
DCCD

Create a text file, Writing Numbers

Recommended Posts

Manjish

Another suggestion :

$f_handle = FileOpen ("c:\millionz.txt",1)

For $i = 1 To 1000000
    FileWriteLine  ($f_handle, $i)
Next

FileClose ($f_handle)

Both methods are correct.. But the one suggested by Zedna, is quicker, n better, if u ask me..


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
Inverted

Based on what ?

I timed mine to 6.1 seconds, whereas the other one to 8.6

$begin = TimerInit()

;==================
$text = ''
For $i = 1 To 1000000
      $text &= $i & @CRLF
Next
FileWrite('C:\million.txt', $text)
;==================

$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)oÝ÷ Ù«­¢+ØÀÌØí¥¸ôQ¥µÉ%¹¥Ð ¤((ìôôôôôôôôôôôôôôôôôô(ÀÌØí}¡¹±ô¥±=Á¸ ÅÕ½ÐíèÀäÈíµ¥±±¥½¹è¹ÑáÐÅÕ½Ðì°Ä¤()½ÈÀÌØí¤ôÄQ¼ÄÀÀÀÀÀÀ(¥±]É¥Ñ1¥¹ ÀÌØí}¡¹±°ÀÌØí¤¤)9áÐ()¥±
±½Í ÀÌØí}¡¹±¤(ìôôôôôôôôôôôôôôôôôô((ÀÌØí¥ôQ¥µÉ¥ ÀÌØí¥¸¤)5Í   ½à À°ÅÕ½ÐíQ¥µ¥É¹ÅÕ½Ðì°ÀÌØí¥¤

Also, mine is safer, as it doesn't grow a string variable to several megabytes.

Share this post


Link to post
Share on other sites
Manjish

Based on what ?

I timed mine to 6.1 seconds, whereas the other one to 8.6

$begin = TimerInit()

;==================
$text = ''
For $i = 1 To 1000000
      $text &= $i & @CRLF
Next
FileWrite('C:\million.txt', $text)
;==================

$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)oÝ÷ Ù«­¢+ØÀÌØí¥¸ôQ¥µÉ%¹¥Ð ¤((ìôôôôôôôôôôôôôôôôôô(ÀÌØí}¡¹±ô¥±=Á¸ ÅÕ½ÐíèÀäÈíµ¥±±¥½¹è¹ÑáÐÅÕ½Ðì°Ä¤()½ÈÀÌØí¤ôÄQ¼ÄÀÀÀÀÀÀ(¥±]É¥Ñ1¥¹ ÀÌØí}¡¹±°ÀÌØí¤¤)9áÐ()¥±
±½Í ÀÌØí}¡¹±¤(ìôôôôôôôôôôôôôôôôôô((ÀÌØí¥ôQ¥µÉ¥ ÀÌØí¥¸¤)5Í   ½à À°ÅÕ½ÐíQ¥µ¥É¹ÅÕ½Ðì°ÀÌØí¥¤

Also, mine is safer, as it doesn't grow a string variable to several megabytes.

Inverted I am sorry..

By mistake i said Zedna.. I did mean ur methos was better.. Thats y i had included ur message in my quote..

A silly typo.. Sorry


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites
Zedna

You can try also combination of both methods:

Play with it and change number in Mod() to see if/what will be better (faster)

$f_handle = FileOpen ("c:\millionz.txt",1)

$text = ''
For $i = 1 To 1000000
    $text &= $i & @CRLF
    If Mod($i,100) = 0 Then
        FileWrite  ($f_handle, $text)
        $text = ''
    EndIf
Next

If $text <> '' Then FileWrite($f_handle, $text)
FileClose ($f_handle)

Share this post


Link to post
Share on other sites
SadBunny

Maybe a stupid question, but just out of curiosity... Why in heaven would you need such a file?


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
Inverted

Nope, in my machine the other 2 versions perform horribly (3 seconds slower)

Zedna, I see you're trying to avoid many consecutive writes to the disk, but it seems there is no big performance hit, maybe because of windows/hard disk cache writing, or memory paging magic.

Also, FileWriteLine seems to be optimized for ... line appending. It performs better than FileWrite and @CRLF.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×