Browse Source

Merge pull request #2315 from nathana1/middleware-fortune-html

A Shawn Bandy 8 years ago
parent
commit
c9f43dfc62

+ 14 - 5
frameworks/CSharp/aspnetcore/Benchmarks/Middleware/MiddlewareHelpers.cs

@@ -2,6 +2,8 @@
 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
 
 using System.Collections.Generic;
+using System.Globalization;
+using System.Text;
 using System.Text.Encodings.Web;
 using System.Threading.Tasks;
 using Benchmarks.Data;
@@ -33,15 +35,22 @@ namespace Benchmarks.Middleware
             httpContext.Response.StatusCode = StatusCodes.Status200OK;
             httpContext.Response.ContentType = "text/html; charset=UTF-8";
 
-            await httpContext.Response.WriteAsync("<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>");
-
+            var sb = new StringBuilder();
+            sb.Append("<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>");
             foreach (var item in model)
             {
-                await httpContext.Response.WriteAsync(
-                    $"<tr><td>{htmlEncoder.Encode(item.Id.ToString())}</td><td>{htmlEncoder.Encode(item.Message)}</td></tr>");
+                sb.Append("<tr><td>");
+                sb.Append(item.Id.ToString(CultureInfo.InvariantCulture));
+                sb.Append("</td><td>");
+                sb.Append(htmlEncoder.Encode(item.Message));
+                sb.Append("</td></tr>");
             }
 
-            await httpContext.Response.WriteAsync("</table></body></html>");
+            sb.Append("</table></body></html>");
+            var response = sb.ToString();
+            // fortunes includes multibyte characters so response.Length is incorrect
+            httpContext.Response.ContentLength = Encoding.UTF8.GetByteCount(response);
+            await httpContext.Response.WriteAsync(response);
         }
     }
 }

+ 6 - 6
frameworks/CSharp/aspnetcore/benchmark_config.json

@@ -57,7 +57,7 @@
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "aspnetcore-linux",
+      "display_name": "aspnetcore-middleware-raw",
       "notes": "",
       "versus": ""
     },
@@ -79,7 +79,7 @@
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "aspnetcore-linux",
+      "display_name": "aspnetcore-middleware-ef",
       "notes": "",
       "versus": ""
     },
@@ -101,7 +101,7 @@
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "aspnetcore-linux",
+      "display_name": "aspnetcore-middleware-dapper",
       "notes": "",
       "versus": ""
     },
@@ -161,7 +161,7 @@
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "aspnetcore-linux",
+      "display_name": "aspnetcore-mvc-raw",
       "notes": "",
       "versus": ""
     },
@@ -183,7 +183,7 @@
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "aspnetcore-linux",
+      "display_name": "aspnetcore-mvc-ef",
       "notes": "",
       "versus": ""
     },
@@ -205,7 +205,7 @@
       "webserver": "None",
       "os": "Linux",
       "database_os": "Linux",
-      "display_name": "aspnetcore-linux",
+      "display_name": "aspnetcore-mvc-dapper",
       "notes": "",
       "versus": ""
     },