def main(): """Measure serialization performance of Random """ r = Random(42) # Measure serialization startSerializationTime = time.time() for i in range(_SERIALIZATION_LOOPS): r.saveToFile("RandonSerialization.stream") elapsedSerializationTime = time.time() - startSerializationTime # Measure deserialization startDeserializationTime = time.time() for _ in range(_DESERIALIZATION_LOOPS): r.loadFromFile("RandonSerialization.stream") elapsedDeserializationTime = time.time() - startDeserializationTime # Print report print(_SERIALIZATION_LOOPS, "Serialization loops in", \ elapsedSerializationTime, "seconds.") print("\t", elapsedSerializationTime/_SERIALIZATION_LOOPS, "seconds per loop.") print(deserializationCount, "Deserialization loops in", \ elapsedDeserializationTime, "seconds.") print("\t", elapsedDeserializationTime/deserializationCount, "seconds per loop.")
def main(): """Measure serialization performance of Random """ r = Random(42) # Measure serialization startSerializationTime = time.time() for i in range(_SERIALIZATION_LOOPS): r.saveToFile("RandonSerialization.stream") elapsedSerializationTime = time.time() - startSerializationTime # Measure deserialization startDeserializationTime = time.time() for _ in range(_DESERIALIZATION_LOOPS): r.loadFromFile("RandonSerialization.stream") elapsedDeserializationTime = time.time() - startDeserializationTime # Print report print(_SERIALIZATION_LOOPS, "Serialization loops in", \ elapsedSerializationTime, "seconds.") print("\t", elapsedSerializationTime / _SERIALIZATION_LOOPS, "seconds per loop.") print(deserializationCount, "Deserialization loops in", \ elapsedDeserializationTime, "seconds.") print("\t", elapsedDeserializationTime / deserializationCount, "seconds per loop.")
def testSerialization(self): """Test serialization of NuPIC randomness.""" path = "RandomSerialization.stream" # Simple test: make sure that dumping / loading works... r = Random(99) r.saveToFile(path) test1 = [r.getUInt32() for _ in range(10)] r = Random(1) r.loadFromFile(path) self.assertEqual(r.getSeed(), 99) test2 = [r.getUInt32() for _ in range(10)] self.assertEqual(test1, test2, "Simple NuPIC random serialization check failed.") # A little tricker: dump / load _after_ some numbers have been generated # (in the first test). Things should still work... # ...the idea of this test is to make sure that the pickle code isn't just # saving the initial seed... r.saveToFile(path) test3 = [r.getUInt32() for _ in range(10)] r = Random() r.loadFromFile(path) self.assertEqual(r.getSeed(), 99) test4 = [r.getUInt32() for _ in range(10)] self.assertEqual( test3, test4, "NuPIC random serialization check didn't work for saving later state." ) self.assertNotEqual( test1, test3, "NuPIC random serialization test gave the same result twice?!?")
def testSerialization(self): """Test serialization of NuPIC randomness.""" path = "RandomSerialization.stream" # Simple test: make sure that dumping / loading works... r = Random(99) r.saveToFile(path) test1 = [r.getUInt32() for _ in range(10)] r = Random(1); r.loadFromFile(path) self.assertEqual(r.getSeed(), 99) test2 = [r.getUInt32() for _ in range(10)] self.assertEqual(test1, test2, "Simple NuPIC random serialization check failed.") # A little tricker: dump / load _after_ some numbers have been generated # (in the first test). Things should still work... # ...the idea of this test is to make sure that the pickle code isn't just # saving the initial seed... r.saveToFile(path) test3 = [r.getUInt32() for _ in range(10)] r = Random(); r.loadFromFile(path) self.assertEqual(r.getSeed(), 99) test4 = [r.getUInt32() for _ in range(10)] self.assertEqual( test3, test4, "NuPIC random serialization check didn't work for saving later state.") self.assertNotEqual( test1, test3, "NuPIC random serialization test gave the same result twice?!?")