Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


how to make this for loop run more effective?

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,47077
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> how to make this for loop run more effective?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 how to make this for loop run more effective? - 5/14/2007 8:50:20 PM   
  sensen9966

 

Posts: 4
Score: 0
Joined: 5/14/2007
Status: offline
nice to find here.

tht .bat file  as followed.


       

when i set the desired_numbers=999999 ,  just mean a similar large number.  the runing time of this script make me boring. 

so anybody can give some advice to improve this script?  thanks a lot.
 
 
Post #: 1
 
 RE: how to make this for loop run more effective? - 5/14/2007 11:37:18 PM   
  SAPIENScripter


Posts: 271
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
There really isn't any way to count from 1 to 100 or whatever range.  Even if you broke the script up so that you could run several scripts concurrently they would each need to be redirected to a separate file and then you'd have to concatenate them. You couldn't have mulitple scripts redirect to the same file.  My suggestion is kick the script off at the end of the day and look at the results in the morning.

As a batch file I don't think you can do any better. Did you want to convert this to PowerShell?  If so, I think you'll see something much different and faster.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to sensen9966)
 
 
Post #: 2
 
 RE: how to make this for loop run more effective? - 5/14/2007 11:42:13 PM   
  SAPIENScripter


Posts: 271
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
If you use PowerShell this should get you the same result but in a fraction of the time compared to the batch file.

$phrases="words"
$limit=10000
$numbers=@(2..$limit)
$phrases > .\dic.txt
$numbers >> .\dic.txt

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to SAPIENScripter)
 
 
Post #: 3
 
 RE: how to make this for loop run more effective? - 5/15/2007 12:40:42 AM   
  sensen9966

 

Posts: 4
Score: 0
Joined: 5/14/2007
Status: offline
quote:

ORIGINAL: SAPIENScripter

If you use PowerShell this should get you the same result but in a fraction of the time compared to the batch file.

$phrases="words"
$limit=10000
$numbers=@(2..$limit)
$phrases > .\dic.txt
$numbers >> .\dic.txt




i have little idea about the Windows PowerShell, but now i have installed it.  and save the above script to a .bat file and run,  but  get some error  info. 
i didn't restart my computer. but can you give me some info about the real run time of the above script?
if set up the $limit=65536, what time we need to wait for?

because the real result i want to get is just a output txt file of some pre-defined phases with the pre-defined number of times to repeat.
so  i  don't care about how to realize it, just find the simple way.

i first try excel use the embed vbs script as followed


      

it very simple and powerful,  i try 65536 , the work time is less than 2second and also easy to control and operate.
but the problem is the row limitation of excel2003 is 65536, so i can't beyond this number to get my desire output.

but some useful info is in excell007 we can beyond this limitation to 1048576, so looks like enough.

anyway thanks, and i am also have a chance to use the powershell because i have install it, i will learn this shell more.

< Message edited by sensen9966 -- 5/15/2007 12:43:47 AM >

(in reply to SAPIENScripter)
 
 
Post #: 4
 
 RE: how to make this for loop run more effective? - 5/15/2007 1:33:06 AM   
  SAPIENScripter


Posts: 271
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
What is posted is not a batch file.  You could run the commands one at a time in PowerShell or save them to a script with a .ps1 extension.  Here's a revised script for you to try:


      

I just ran it and it finished in 24 seconds.  I also discovered that the limit for the array, @(2..$limit) is 50000.

Save this code as Make-Dic.ps1.  Open a powerShell prompt and go to the directory where the file is saved.  Run: .\make-dic.ps1

You need to include the path.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to sensen9966)
 
 
Post #: 5
 
 RE: how to make this for loop run more effective? - 5/16/2007 12:45:48 AM   
  sensen9966

 

Posts: 4
Score: 0
Joined: 5/14/2007
Status: offline
after Set ExecutionPolicy to RemoteSigned,   i  get the same result of runing your script. thanks.

it's there some comparison review between the powershell and other script language?

(in reply to SAPIENScripter)
 
 
Post #: 6
 
 RE: how to make this for loop run more effective? - 5/16/2007 3:27:10 AM   
  SAPIENScripter


Posts: 271
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
You might want to start here:
http://www.microsoft.com/technet/scriptcenter/topics/winpsh/convert/default.mspx

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

Follow Me: http://www.twitter.com/JeffHicks

(in reply to sensen9966)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> how to make this for loop run more effective? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts