Answer the question
In order to leave comments, you need to log in
ASP.NET Core must be slow?
I created an ASP.NET Core project in the studio and
got such a class there
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
class Program
{
static void Main(string[] args)
{
MyWeb web = new MyWeb();
Thread.Sleep(100);
for (int i = 0; i < 10; i++)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
web.Send("http://localhost:5000/api/values/");
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds);
Console.WriteLine("RunTime " + elapsedTime);
}
Console.ReadLine();
}
public class MyWeb
{
public MyWebResponse Send(string url)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.KeepAlive = false;
//request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
request.Timeout = 20000;
//request.ContentType = "application/x-www-form-urlencoded";
//request.UserAgent = "Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.9.168 Version/11.51";
/*
request.Method = "POST";
request.CookieContainer = cc;
string command = @"" + data;
byte[] bytes = Encoding.ASCII.GetBytes(command);
request.ContentLength = bytes.Length;
Stream stream = request.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
*/
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string ret = reader.ReadToEnd();
return new MyWebResponse()
{
text = ret
};
}
}
public class MyWebResponse
{
public string text;
}
}
RunTime 00:00:02.930
RunTime 00:00:00.089
RunTime 00:00:00.082
RunTime 00:00:00.066
RunTime 00:00:02.291
RunTime 00:00:00.176
RunTime 00:00:00.555
RunTime 00:00:00.243
RunTime 00:00:00.360
RunTime 00:00:00.412
static void Main(string[] args)
{
WebSocketSharp.Server.HttpServer t = new WebSocketSharp.Server.HttpServer(IPAddress.Any,5000);
t.OnGet += T_OnGet;
t.Start();
Console.ReadLine();
}
private static void T_OnGet(object sender, WebSocketSharp.Server.HttpRequestEventArgs e)
{
Console.WriteLine(e.Request.Url);
string[] data_ = new string[] { "key","val" };
Newtonsoft.Json.JsonConvert.SerializeObject(data_);
var data = Encoding.UTF8.GetBytes("ddd");
e.Response.WriteContent(data);
}
Answer the question
In order to leave comments, you need to log in
Absolutely nothing is said about setting up asp.net core. I can advise you to turn off logging to the console. Make a release version and run separately from the studio.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question