Skip to content

Commit d56a876

Browse files
committed
Only update RFC 1123 once per second
Text only changes once per second; not fastest and allocates but moves it out of hot path
1 parent 634eb65 commit d56a876

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

experimental/ManagedRIOHttpServer/Program.cs

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace ManagedRIOHttpServer
1212
{
1313
public sealed class Program
1414
{
15+
// Number of 100ns ticks per time unit
16+
private const long TicksPerMillisecond = 10000;
17+
private const long TicksPerSecond = TicksPerMillisecond * 1000;
18+
1519
static readonly string headersKeepAliveStr = "HTTP/1.1 200 OK\r\n" +
1620
"Content-Type: text/plain\r\n" +
1721
"Content-Length:13\r\n" +
@@ -106,6 +110,7 @@ static async Task ServeSocket(RIOTcpConnection socket)
106110

107111
var loop = 0;
108112
var overflow = 0;
113+
var lastSeconds = 0L;
109114
// need to check for keep alive
110115

111116
while (true)
@@ -272,10 +277,15 @@ static async Task ServeSocket(RIOTcpConnection socket)
272277
socket.SendCachedBad();
273278
break;
274279
}
275-
276-
var date = DateTime.UtcNow.ToString("r");
277-
Encoding.UTF8.GetBytes(date, 0, dateBytes.Length, dateBytes, 0);
278-
280+
281+
var now = DateTime.UtcNow;
282+
var ticks = now.Ticks / TicksPerSecond;
283+
if (lastSeconds != ticks) {
284+
lastSeconds = ticks;
285+
var date = now.ToString("r");
286+
Encoding.ASCII.GetBytes(date, 0, dateBytes.Length, dateBytes, 0);
287+
}
288+
279289
for (var i = 1; i < count; i++)
280290
{
281291
socket.QueueSend(headerBuffer, false);
@@ -301,27 +311,30 @@ static async Task ServeSocket(RIOTcpConnection socket)
301311
}
302312
}
303313

304-
305-
public static void LowerCaseSIMD(byte[] data)
306-
{
307-
var A = new Vector<byte>(65); // A
308-
var Z = new Vector<byte>(90); // Z
314+
//public static void LowerCaseSIMD(ArraySegment<byte> data)
315+
//{
316+
// if (data.Offset + data.Count + Vector<byte>.Count < data.Array.Length)
317+
// {
318+
// throw new ArgumentOutOfRangeException("Nope");
319+
// }
320+
// var A = new Vector<byte>(65); // A
321+
// var Z = new Vector<byte>(90); // Z
309322

310-
for (var o = 0; o < data.Length - Vector<byte>.Count; o += Vector<byte>.Count)
311-
{
312-
var v = new Vector<byte>(data, o);
313-
314-
v = Vector.ConditionalSelect(
315-
Vector.BitwiseAnd(
316-
Vector.GreaterThanOrEqual(v, A),
317-
Vector.LessThanOrEqual(v, Z)
318-
),
319-
Vector.BitwiseOr(new Vector<byte>(0x20), v), // 0010 0000
320-
v
321-
);
322-
v.CopyTo(data, o);
323-
}
324-
}
323+
// for (var o = data.Offset; o < data.Count - Vector<byte>.Count; o += Vector<byte>.Count)
324+
// {
325+
// var v = new Vector<byte>(data.Array, o);
326+
327+
// v = Vector.ConditionalSelect(
328+
// Vector.BitwiseAnd(
329+
// Vector.GreaterThanOrEqual(v, A),
330+
// Vector.LessThanOrEqual(v, Z)
331+
// ),
332+
// Vector.BitwiseOr(new Vector<byte>(0x20), v), // 0010 0000
333+
// v
334+
// );
335+
// v.CopyTo(data.Array, o);
336+
// }
337+
//}
325338
}
326339

327340
}

0 commit comments

Comments
 (0)