Jump to content

Create a text file, Writing Numbers


DCCD
 Share

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...