public unsafe static void EncodeDecodeTest(int count) { byte[] bytes = new byte[count * 5]; uint[] src = new uint[count]; uint[] dst = new uint[count]; uint v1 = 0, v2 = 0, v3 = 0, v4 = 0; int pos = 0; int apos = 0, n = 0; for (int i = 0; i < count; i += 4) { GroupVarintUtils.GetValues(out v1, out v2, out v3, out v4); src[i] = v1; src[i + 1] = v2; src[i + 2] = v3; src[i + 3] = v4; } Stopwatch watch = Stopwatch.StartNew(); pos = GroupVarintCodec.Encode(bytes, 0, src, 0, src.Length); int encodeCost = (int)watch.ElapsedMilliseconds; watch = Stopwatch.StartNew(); //n = GroupVarintCodec.Decode(bytes, 0, pos, dst, ref apos); for (int i = 0; i < 100000; i++) { apos = 0; //n = GroupVarintCodec.Decode(bytes, 0, pos, dst, ref apos); n = DecodeForTestA(bytes, 0, pos, dst, ref apos); } int decodeCost = (int)watch.ElapsedMilliseconds; int errorCount = 0; for (int i = 0; i < count; i++) { if (src[i] != dst[i]) { errorCount++; } } string rs = $"encodeCost:{encodeCost}" + $"decodeCost:{decodeCost}" + $"errorCount:{errorCount}"; Console.WriteLine(rs); }
public unsafe static int GetLenthLookupCode(uint[] arr) { int len = 0; fixed(int *p1 = &codeIdx[0], p2 = &lenId2[0]) { for (int i = 0; i < arr.Length; i += 4) { len += GroupVarintCodec.GetByteSize(arr[i], p1, p2); len += GroupVarintCodec.GetByteSize(arr[i + 1], p1, p2); len += GroupVarintCodec.GetByteSize(arr[i + 2], p1, p2); len += GroupVarintCodec.GetByteSize(arr[i + 3], p1, p2); } } return(len); }