Created
May 3, 2013 18:04
-
-
Save fxg42/5512113 to your computer and use it in GitHub Desktop.
Check time between remote and local calls...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
Author
fxg42
commented
May 3, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment