DCCD Posted February 6, 2009 Posted February 6, 2009 Hey guys, I want to create text file ,and Write 1000000 numbers starting from 0 , ex:text file ============ 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 .... ..... ..... ...... 1000000 ============ is it possible? [u][font=Arial Black]M[/font]y Blog, AVSS Parts[/u][font=Arial Black]Else[/font][font=Arial Black]L[/font]ibya Linux Users Group
Zedna Posted February 6, 2009 Posted February 6, 2009 Yes. $text = '' For $i = 1 To 1000000 $text &= $i & @CRLF Next FileWrite('C:\million.txt', $text) Resources UDF ResourcesEx UDF AutoIt Forum Search
DCCD Posted February 6, 2009 Author Posted February 6, 2009 Thanks A Lot [u][font=Arial Black]M[/font]y Blog, AVSS Parts[/u][font=Arial Black]Else[/font][font=Arial Black]L[/font]ibya Linux Users Group
Inverted Posted February 6, 2009 Posted February 6, 2009 Another suggestion : $f_handle = FileOpen ("c:\millionz.txt",1) For $i = 1 To 1000000 FileWriteLine ($f_handle, $i) Next FileClose ($f_handle)
Manjish Posted February 6, 2009 Posted February 6, 2009 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
Inverted Posted February 6, 2009 Posted February 6, 2009 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.
Manjish Posted February 6, 2009 Posted February 6, 2009 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
Zedna Posted February 6, 2009 Posted February 6, 2009 Try this $f_handle = FileOpen ("c:\millionz.txt",1) For $i = 1 To 1000000 FileWrite ($f_handle, $i & @CRLF) Next FileClose ($f_handle) Resources UDF ResourcesEx UDF AutoIt Forum Search
Zedna Posted February 6, 2009 Posted February 6, 2009 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) Resources UDF ResourcesEx UDF AutoIt Forum Search
SadBunny Posted February 6, 2009 Posted February 6, 2009 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.
Inverted Posted February 7, 2009 Posted February 7, 2009 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now