Remote procedure call vs do shell script

I was intresting to know the performance of XMLRPC vs do shell script.
So I made a little sample of 100 number of iterations

tell methodCall to methodName:"add" params:{2, 3}

script methodCall
	on methodName:methodName params:params
		tell application "http://localhost:7080"
			call xmlrpc {method name:methodName, parameters:params}
		end tell
	end methodName:params:
end script
do shell script "expr 2 + 3"

The first script is XMLRPC version and second is do shell script, here is the result.

Here the average is not important but more the Total Time. To run 100 iterations is not normal for do shell script. But it seams to me that there is something that slow it down.
compare to remote procedure call. That is more optimized for many calls.

What XMLRPC server/service are you running?

I use Twisted Twisted · PyPI Its a python module.

You could read more here https://twisted.org the homepage of Twisted

Also, why are the averages showing the same number?

It could be that average is not caculated for 100 iterations.
You could ask Shane Stanley

And if I run the same example 5 times it will give different numbers.

The averages are actually calculated for the given number of iterations.
The results are the same because of the rounding behavior:

use framework "Foundation"
use framework "AppKit"
use scripting additions

set theIteration to 100
set timeA to my formatLaps:(0.157) iteration:theIteration decimals:3 --> 0.002
set timeB to my formatLaps:(0.234) iteration:theIteration decimals:3 --> 0.002
set timeC to my formatLaps:(0.157) iteration:theIteration decimals:4 --> 0.0016
set timeD to my formatLaps:(0.234) iteration:theIteration decimals:4 --> 0.0023
{timeA, timeB, timeC, timeD}

on formatLaps:theLaps iteration:theIteration decimals:theDeci
	set theFormatter to current application's NSNumberFormatter's new()
	theFormatter's setMinimumFractionDigits:theDeci
	theFormatter's setMaximumFractionDigits:theDeci
	set theResult to theFormatter's numberFromString:(theFormatter's stringFromNumber:(theLaps / theIteration))
	return theResult as string
end formatLaps:iteration:decimals:

Why the total time is less for XMLRPC call could maybe be that the Twisted framework is
An asynchronous networking framework. On other hand I’m not sure if RPC call could drop the response before other request is made. That maybe is not true for do shell script.
I guess only the status of request could tell if that is happen.