Created
October 11, 2012 20:46
-
-
Save darrelmiller/3875371 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Web API using WCF to Self-host | |
//Time to create init Server and Start HttpListener: 0 | |
//Time for roundtrip: 302 body = {"Foo":"Bar"} | |
//Time for 2nd roundtrip (new WebRequest): 0 Body = {"Foo":"Bar"} | |
//Servicestack | |
//Time to create init AppHost and Start HttpListener: 129 | |
//Time for roundtrip: 176 body = {"Foo":"Bar"} | |
//Time for 2nd roundtrip (new WebRequest): 0 Body = {"Foo":"Bar"} | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Net.Http; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Web.Http; | |
using System.Web.Http.SelfHost; | |
namespace ConsoleApplication3 | |
{ | |
public class Test | |
{ | |
public string Foo { get; set; } | |
} | |
public class TestController : ApiController | |
{ | |
public Test Get([FromUri]Test request) | |
{ | |
return new Test { Foo = request.Foo }; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) { | |
Stopwatch s = new Stopwatch(); | |
var config = new HttpSelfHostConfiguration("http://localhost:8080"); | |
config.Routes.MapHttpRoute("default", "json/syncreply/{controller}"); | |
var server = new HttpSelfHostServer(config); | |
server.OpenAsync().Wait(); | |
s.Stop(); | |
Console.WriteLine("Time to create init Server and Start HttpListener: " + s.ElapsedMilliseconds); | |
s.Reset(); | |
s.Start(); | |
var client = new HttpClient(); | |
var body = client.GetAsync("http://localhost:8080/json/syncreply/Test?Foo=Bar").Result.Content.ReadAsStringAsync().Result; | |
s.Stop(); | |
Console.WriteLine("Time for roundtrip: " + s.ElapsedMilliseconds + " body = " + body); | |
s.Reset(); | |
s.Start(); | |
body = client.GetAsync("http://localhost:8080/json/syncreply/Test?Foo=Bar").Result.Content.ReadAsStringAsync().Result; | |
s.Stop(); | |
Console.WriteLine("Time for 2nd roundtrip (new WebRequest / No keep-alive): " + s.ElapsedMilliseconds + " Body = " + body); | |
Console.ReadLine(); | |
server.CloseAsync().Wait(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment