lemming Posted May 29, 2010 Report Share Posted May 29, 2010 Here's not one, but two sort algorithms implemented in MEP. The first is the classic Bubble Sort algorithm, while the second is Gnome Sort, described as "the simplest sort algorithm". These are "pure" macros - no external programs, scripts or libraries are used. I didn't even use dynamic variables! (i.e. Run Macro in Variable). However, they only work with MEP, because they both need arrays. These scripts' performance are better than my old ME3 Bubble Sort script, but they're still slow - many orders of magnitude slower than the built-in sorting functions available in other programming languages and script languages. UPDATE 1: I cleaned up the code a bit and added more comments. Thanks, Paul. Pls delete any ver 0.8 files you have, and download the latest. UPDATE 2: Tweaked the code for better performance, updated benchmarks and added an installation guide. Pls download the latest files below and delete old versions. Benchmarks on an old machine running Win XP (P4 3GHz Northwood, about 5 years old): Bubble Sort 100 elements = about 1.0 sec 250 elements = about 5.7 sec 500 elements = about 24.7 sec Gnome Sort 100 elements = about 1.2 sec 250 elements = about 6.6 sec 500 elements = about 30.3 sec You can easily conduct your own benchmarking because I've included code for reporting the start and end time. Comments are appreciated. Regards, Lemming Quote Link to comment Share on other sites More sharing options...
lemming Posted May 29, 2010 Author Report Share Posted May 29, 2010 Other input files for testing. Also, a few webpages I refered to: Gnome Sort (Wikipedia) http://en.wikipedia.org/wiki/Gnome_sort Bubble Sort (Wikipedia) http://en.wikipedia.org/wiki/Bubble_sort Visualization of Quick sort IMDB Top 10.txt IMDB Top 50.txt IMDB Top 100.txt Top 500 Girl\'s names 2009.txt Quote Link to comment Share on other sites More sharing options...
paul Posted May 30, 2010 Report Share Posted May 30, 2010 The code is also a kludgy. MEP can't seem to perform logic operations on nested variables like %movie%loopcounter%% so I had to use intermediate variables. 1) If you make %movie% an array, then %movie[%loopcounter%]% works just fine. When %loopcounter% is 1, this represents %movie[1]%, etc. 2) I wrote this macro: Variable Set String %tString1% to "String1Value" Variable Set String %tString2% to "String2Value" Variable Set Integer %nIndex% to 1 Text Box Display: --String1 = %tString%nIndex%% Variable Set Integer %nIndex% to 2 Text Box Display: String2 = %tString%nIndex%% And the macro displayed String1 = String1Value followed by String2 = String2Value Quote Link to comment Share on other sites More sharing options...
lemming Posted May 30, 2010 Author Report Share Posted May 30, 2010 Thanks for the tip, Paul. It works now. Turns out I was missing some punctuation. I updated my code and got a slight performance boost. 1) If you make %movie% an array, then %movie[%loopcounter%]% works just fine. When %loopcounter% is 1, this represents %movie[1]%, etc. 2) I wrote this macro: Variable Set String %tString1% to "String1Value" Variable Set String %tString2% to "String2Value" Variable Set Integer %nIndex% to 1 Text Box Display: --String1 = %tString%nIndex%% Variable Set Integer %nIndex% to 2 Text Box Display: String2 = %tString%nIndex%% And the macro displayed String1 = String1Value followed by String2 = String2Value Quote Link to comment Share on other sites More sharing options...
dwcolbeth Posted June 11, 2010 Report Share Posted June 11, 2010 When trying to import it says: Specified file is not supported in MEX? When trying to run it says password is needed? Quote Link to comment Share on other sites More sharing options...
lemming Posted June 16, 2010 Author Report Share Posted June 16, 2010 Hi David et al, I am tweaking the scripts and will post updated versions soon, with a step-by-step installation guide. Stay tuned! BTW, the password dialog is probably from Windows Vista or Windows 7; my code does not include passwords. Also, these script need Macro Express Pro. -Lemming When trying to import it says: Specified file is not supported in MEX? When trying to run it says password is needed? Quote Link to comment Share on other sites More sharing options...
dwcolbeth Posted June 17, 2010 Report Share Posted June 17, 2010 Drat, I only have the 'basic' version of ME. Is there a mod I can do to allow for standard ME? What code differences are you implementing that ME Pro requires? PS: If it were just me, I'd opt for the $20, but we have several hundred users in the Company that I am contracting for so that would be too cost prohibitive. Hi David et al, I am tweaking the scripts and will post updated versions soon, with a step-by-step installation guide. Stay tuned! BTW, the password dialog is probably from Windows Vista or Windows 7; my code does not include passwords. Also, these script need Macro Express Pro. -Lemming Quote Link to comment Share on other sites More sharing options...
lemming Posted June 25, 2010 Author Report Share Posted June 25, 2010 1. Download the sort scripts (.mex) from the Macro Express Forums, i.e. from this page. 2. Download the test data (.txt) from Macro Express Forums. Take note of the file location for later use. 3. Import the sort scripts from the downloaded .mex file into Macro Express Pro. Click File->Import->Import Macros… In this example, the file is Bubble Sort demo (strings) v 0.9.1 MEP.mex. Click Open. In the Import Macros window, click Select All and click OK. 4. You will now need to modify the scripts to work on your system. Basically, change the locations for the input and output files. In the Macro Express Pro Explorer window, double-click on the sort script to open it in the Script Editor window. Change the lines that start with “Variable Set String %SourceFile%” and “Variable Set String %ResourceFile%”. Just change the path to where the text source file is on your system. Click OK when you’re done and close the Script Editor window. 5. You can now run the script. There is no hotkey; just click on the script to select it, then click the “play” button in the Macro Express Pro Explorer window. Open “sorted listed.txt” to check the results. Other things to note: - The sorts are in ascending order (A to Z) - Hint for Win Vista/Win 7 users – don’t save input and output files to C:\ - The default input file is "Top xx movies.txt". Change as needed. - The default output file name is "sorted.txt". Change as needed. - Any existing output file with the same name is deleted every time the scripts are run. - There is very little error-handling - The array size must be known beforehand. I don't know how to assign it dynamically. To change the array size, go to Script Editor window->Variables->Text Variables - I haven't tested it with numbers (numerical sorting), but that should be trivial to implement. Gnome Sort demo (strings) v 0.9.1 MEP.mex Bubble Sort demo (strings) v 0.9.1 MEP.mex Top 500 movies.txt Top 100 movies.txt Top 250 movies.txt Quote Link to comment Share on other sites More sharing options...
lemming Posted June 25, 2010 Author Report Share Posted June 25, 2010 The key new feature in MEP is the arrays. It's very difficult to implement sorting without arrays. I actually did write a bubble sort for ME a few years ago. It was very hard to understand and maintain. Heck, even I don't know how it works now. I consider it deprecated. As for the company you're contracting for - do all the users need sorting code? If not, just upgrade a few of them at a time. -Lemming. Drat, I only have the 'basic' version of ME. Is there a mod I can do to allow for standard ME? What code differences are you implementing that ME Pro requires? PS: If it were just me, I'd opt for the $20, but we have several hundred users in the Company that I am contracting for so that would be too cost prohibitive. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.