I have added PostMessage to my testing application and it came in slower than SendMessage.
Calling PostMessage X 5000000
9.199 seconds for PostMessage
Calling SendMessage X 5000000
1.594 seconds for SendMessage
Calling callback X 5000000
0.250 seconds for Callback
This is between my DLL and EXE, the DLL is notifing the EXE by using many calls to the EXE's main form handle via PostMessage, SendMessage... I also did a Callback for comparison. Of course this test is not inter-process, but now you can see why I wanted to use a Callback in IPC
Maybe my test is not accounting for async vs sync (PostMessage vs SendMessage) calling methods?
Here is the meat of how I tested:
In the DLL:
Code: Select all
procedure Send_PostMessage(mode, opt: integer); stdcall; begin PostMessage(CB_Handle, WM_USER + 10, mode, opt); end;
Code: Select all
procedure SetCallBackFunc(myCBFunction: TCallBackFunction); stdcall; external 'messageDLL.dll'; procedure TestCallBack(myCBFunction: TCallBackFunction); stdcall; external 'messageDLL.dll'; procedure Send_PostMessage(mode, opt: integer); stdcall; external 'messageDLL.dll'; procedure Send_SendMessage(mode, opt: integer); stdcall; external 'messageDLL.dll'; ... // for each I am doing... SW := TStopwatch.StartNew; for ci := 1 to NumMessages do begin case which of 1: Send_PostMessage(1, 1); 2: Send_SendMessage(1, 1); 3: TestCallBack(CallMeTest); end; end; SW.Stop(); Display(Format('%.3f seconds for '+ss, [SW.Elapsed.TotalSeconds]));
Callbacks are ultra fast within the same process. But simple callbacks like that don't work across process boundaries.
In any case, of course you can measure SendMessage vs PostMessage across process boundaries and measure which is faster. I would assume PostMessage should be faster. Speed can be measured in different ways, though:
1) How long does the Post/SendMessage call take in the other process?
2) How high is the average delay between sending the message and receiving it in your Delphi process.
It's quite possible that some methods are better for 1) and others for 2). So in order to get a full picture, you should probably measure both.