示例#1
0
    private void SerializeTestObject <T>(Action <IEnumerable <T>, Stream> serializeFn) where T : ITestObject, new()
    {
        var output = new ByteCountingStream();
        var value  = new T();

        value.Fill();
        var sw = Stopwatch.StartNew();

        // warmup
        //UnityEngine.Debug.Log(string.Format("[{0}] Warming-up {1} Serializer", typeof(T).Name, serializeFn.Method.DeclaringType.Name));
        serializeFn(InfiniteEnumerable(value).Take(ItemsToSerialize / 100), output);

        //UnityEngine.Debug.Log(string.Format("[{0}] Running {1} Serializer", typeof(T).Name, serializeFn.Method.DeclaringType.Name));
        // reset
        GC.Collect();
        output.SetLength(0);
        sw.Start();
        serializeFn(InfiniteEnumerable(value).Take(ItemsToSerialize), output);
        sw.Stop();
        //UnityEngine.Debug.Log(string.Format("[{0}] {1} Serializer finished in {2:F2}ms, {3} bytes are written.", typeof(T).Name, serializeFn.Method.DeclaringType.Name, sw.ElapsedMilliseconds, output.Length));
        UnityEngine.Debug.Log(string.Format("[{0}] {1} | size(bytes) {2} | object/s {3:F0} | bandwidth {4:F2} Mb/s", typeof(T).Name, serializeFn.Method.DeclaringType.Name,
                                            output.Length / ItemsToSerialize,
                                            ItemsToSerialize * (1 / sw.Elapsed.TotalSeconds),
                                            output.Length * (1 / sw.Elapsed.TotalSeconds) / 1024 / 1024));
    }