I improved the program for memory usage test with HMG_Upper() function:
- added Upper() test,
- added MY_Upper() function and its test,
- added info about execution time.
Code: Select all
// Press 'Test: ...' and observe memory usage at status bar
#include 'hmg.ch'
FUNCTION Main()
SET FONT TO 'MS Shell Dlg', 8
DEFINE WINDOW MUT_WA;
COL 200;
ROW 100;
WIDTH 180;
HEIGHT 210;
TITLE 'Memory usage test';
MAIN;
MINBUTTON .F.;
MAXBUTTON .F.
DEFINE BUTTON Test_BU1
COL 10
ROW 20
WIDTH 150
HEIGHT 25
CAPTION 'Test: HMG_Upper()'
ACTION DoTest(1, 'HMG_Upper()')
END BUTTON
DEFINE BUTTON Test_BU2
COL 10
ROW 50
WIDTH 150
HEIGHT 25
CAPTION 'Test: Upper()'
ACTION DoTest(2, 'Upper()')
END BUTTON
DEFINE BUTTON Test_BU3
COL 10
ROW 80
WIDTH 150
HEIGHT 25
CAPTION 'Test: MY_Upper()'
ACTION DoTest(3, 'MY_Upper()')
END BUTTON
DEFINE BUTTON Exit_BU
COL 10
ROW 110
WIDTH 150
HEIGHT 25
CAPTION 'Exit'
ACTION MUT_WA.RELEASE
END BUTTON
DEFINE STATUSBAR
STATUSITEM ''
END STATUSBAR
DEFINE TIMER MUT_WA_TI;
INTERVAL 1000;
ACTION UpdateStatus()
ON KEY ESCAPE ACTION MUT_WA.RELEASE
END WINDOW //MUT_WA
UpdateStatus()
MUT_WA.ACTIVATE
RETURN NIL
FUNCTION DoTest(nTest, cTitle)
LOCAL cLowerStr := 'abcdefghijklmnop'
LOCAL cUpperStr
LOCAL nSeconds
LOCAL cTime
LOCAL n
nSeconds := Seconds()
SWITCH nTest
CASE 1
FOR n := 1 TO 100000
cUpperStr := HMG_Upper(cLowerStr)
NEXT
EXIT
CASE 2
FOR n := 1 TO 100000
cUpperStr := Upper(cLowerStr)
NEXT
EXIT
CASE 3
FOR n := 1 TO 100000
cUpperStr := MY_Upper(cLowerStr)
NEXT
ENDSWITCH
cTime := Str((Seconds() - nSeconds) * 1000, 5)
UpdateStatus()
MsgBox('Lower: ' + cLowerStr + CRLF + 'Upper: ' + cUpperStr + CRLF + 'Time: ' + cTime + ' ms', cTitle)
RETURN NIL
FUNCTION UpdateStatus()
MUT_WA.STATUSBAR.Item(1) := 'Memory usage: ' + LTrim(Str(GetProcessMemoryInfo()[3] / 1024, 10, 0) + ' KB')
//RELEASE MEMORY does not work in Win-XP, in Win-7 works
//RELEASE MEMORY
RETURN NIL
FUNCTION MY_Upper(cString)
IF ! (cString == '')
HMG_CallDLL('User32.dll', 0, 'CharUpper', @cString)
ENDIF
RETURN cString
Conclusions from the test:
- HMG_Upper() each time increases memory usage (on Win-XP "RELEASE MEMORY" is ineffective). Upper() and MY_Upper() works properly.
- Upper() does not support Unicode. HMG_Upper() and MY_Upper() supports Unicode and ANSI.
- Upper() is the fastest, HMG_Upper() is about 3 times slower, MY_Upper() is about 18 times slower.
Why HMG_Upper() function is important in the context of memory usage?
Because it is used in the functions GetProperty(), SetProperty() and DoMethod().
It seems to me that in these cases, it can be replaced with Upper().