Message-ID: <3427709F.1212@EnchantedLearning.com> Date: Tue, 23 Sep 1997 00:33:34 -0700 From: Mitchell Spector Reply-To: spector AT EnchantedLearning DOT com Organization: Enchanted Learning Software MIME-Version: 1.0 To: djgpp AT delorie DOT com, "Salvador Eduardo Tropea (SET)" , Eli Zaretskii Subject: Clipboard timing, strange results, Rhide (Was: DJGPP, interprocess communication, and DPMI) References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk I tried timing the WINOLDAP clipboard interrupts, and the results surprised me. (Timing routines often do that. :-) The loop below will repeatedly open and close the Windows clipboard for 10 seconds, counting the number of iterations. Any useful work with the clipboard (getting the data or its size, or setting the data) is over and above this, but this is at least a baseline. Save the code below as clip1.cc. I compiled it with the command " gcc -Wall -o clip1.exe clip1.cc ". The machine I tested it on has a 133-MHz Pentium processor -- just a reference point for anybody else who tries it. I ran it in a DOS box under Windows95, and found that I got 40-50 iterations per second. That's slow, but that's not the surprising part. The surprising part came when I launched Rhide, spawned a DOS shell from within Rhide (using the DOS shell menu item), and found that I got between 700 and 850 iterations per second! This is completely repeatable. Running the program by double-clicking on the clip1.exe icon yields about 50 iterations per second; also starting a DOS box from the Start menu and running clip1 from the command line in that DOS box yields about 50 iterations per second. But starting Rhide in Win95, spawning a DOS box from Rhide, and running clip1 from the command line in that DOS box consistently yields around 800 iterations per second. Does anybody know what difference there is between a DOS box spawned directly by Win95 and a DOS shell spawned by Rhide that could account for a 15-fold speed improvement when running under Rhide's DOS shell? Are interrupts handled differently in some way? Notice that I don't have to compile using Rhide, so it can't be my current Rhide optimization settings, for instance. I'm just using Rhide as a gateway to a DOS shell and then running literally the same exe that I ran before, only with much faster execution of the interrupts. I checked the various PIF's, but I don't see any differences between them (the PIF memory settings for DPMI memory, etc., are all Win95's stock "Auto" setting). When I remove the interrupts from the program entirely, leaving just the overhead (loop, timing, and counting), the difference disappears, and I get around 3 million iterations per second, whether via Rhide or not. (Incidentally, this shows that the overhead is insignificant and that the interrupts themselves are very, very slow.) Any ideas? (See the code at the end of this posting, after my signature.) Mitchell -- Mitchell Spector, Enchanted Learning Software E-mail: spector AT EnchantedLearning DOT com Visit ZoomDinosaurs, the first hypertext book for children about dinosaurs. -- http://www.EnchantedLearning.com/subjects/dinosaurs -- Here's the code: // clip1.cc #include #include #include const int IntWin = 0x2f; const int InterruptFunctionIdentifyWinOldApVersion = 0x1700; const int InterruptFunctionOpenClipboard = 0x1701; const int InterruptFunctionEmptyClipboard = 0x1702; const int InterruptFunctionSetClipboardData = 0x1703; const int InterruptFunctionGetClipboardDataSize = 0x1704; const int InterruptFunctionGetClipboardData = 0x1705; const int InterruptFunctionCloseClipboard = 0x1708; const int ClipboardFormatText = 1; const int WinOldApBadVersion = 0x1700; const int NumberOfSeconds = 10; // Duration of test int main(void) { __dpmi_regs r; clock_t ClockGoal; const clock_t durationInTicks = CLOCKS_PER_SEC * NumberOfSeconds; long count = 0; r.x.ax = InterruptFunctionIdentifyWinOldApVersion; __dpmi_int(IntWin, &r); if (WinOldApBadVersion == r.x.ax) { printf("Doesn't support WINOLDAP clipboard interrupts\n"); return 1; } printf("WINOLDAP Version %hu.%hu\n", r.h.al, r.h.ah); ClockGoal = clock() + durationInTicks; while (clock() < ClockGoal) { r.x.ax = InterruptFunctionOpenClipboard; __dpmi_int(IntWin, &r); if (0 == r.x.ax) { printf("Error: Opening clipboard\n"); return 2; } r.x.ax = InterruptFunctionCloseClipboard; __dpmi_int(IntWin, &r); if (0 == r.x.ax) { printf("Error: Closing clipboard\n"); return 3; } count++; } printf("Opened and closed clipboard approximately %ld times per sec\n", (count + NumberOfSeconds/2)/NumberOfSeconds); return 0; } // main