Skip to content

Instantly share code, notes, and snippets.

@fxg42
Created May 3, 2013 18:04
Show Gist options
  • Save fxg42/5512113 to your computer and use it in GitHub Desktop.
Save fxg42/5512113 to your computer and use it in GitHub Desktop.
Check time between remote and local calls...
@Grab('org.codehaus.groovy.modules:groovyws:0.5.2')
import groovyx.net.ws.*
// Define a simple service with a single method that sums two numbers.
class MathService {
double add (double x, double y) { x + y }
}
// Start a server that exposes the service as a SOAP endpoint.
WS_URL = 'http://localhost:6980/MathService'
Thread.start {
new WSServer().with {
setNode('MathService', WS_URL)
start()
}
}.join()
// Initialize and connect a SOAP client to the server.
remote = new WSClient("${WS_URL}?wsdl", this.class.classLoader)
remote.initialize()
// Initialize a local service instance.
local = new MathService()
// Execute a function 1000 times and return the time it took to do it.
def timed (fn) {
start = new Date()
1000.times(fn)
new Date().time - start.time
}
// Time the execution of a remote call and of a local call.
println "remote : ${timed { remote.add(1d, 2d) }} ms."
println "local : ${timed { local.add(1d, 2d) }} ms."
// Force quit.
System.exit(0)
@fxg42
Copy link
Author

fxg42 commented May 3, 2013

remote : 3160 ms.
local  : 9 ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment