#DOCUMENTATION by cg
authorClaus Gittinger <cg@exept.de>
Sun, 17 Mar 2019 20:15:30 +0100
changeset 4877 70700688e4e4
parent 4876 0ad921aed93f
child 4878 5d852ae34bc9
#DOCUMENTATION by cg class: CRC32Stream class comment/format in: #documentation #examples
CRC32Stream.st
--- a/CRC32Stream.st	Sun Mar 17 18:35:19 2019 +0100
+++ b/CRC32Stream.st	Sun Mar 17 20:15:30 2019 +0100
@@ -96,37 +96,37 @@
     Standard CRC method as defined by ISO 3309 [ISO-3309] or ITU-T V.42 [ITU-T-V42].
     The default CRC polynomial employed is
 
-	x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
-	(or 16r04C11DB7)
+        x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
+        (or 16r04C11DB7)
 
     You can also create an instace performing the Castagnoli CRC-32C
     (used in iSCSI & SCTP [RFC3720], G.hn payload, SSE4.2):
 
-	self newCrc32c
+        self newCrc32c
 
-	poly: 16r1edc6f41
-	= x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1
+        poly: 16r1edc6f41
+        = x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1
 
     Notice that this CRC is also used with PNG images;
     therefore, its performance directly affects png image processing (png write speed).
 
     throughput:
-	235 Mb/s on MacBook Pro (2.6Ghz I7)
-	157 Mb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit)
-	150 Mb/s on 2Ghz Duo
+        235 Mb/s on MacBook Pro (2.6Ghz I7) (360 Mb/s for big chunks)
+        157 Mb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit)
+        150 Mb/s on 2Ghz Duo
      new:
-	500 Mb/s for castagnoli on MacBook Pro (2.6Ghz I7)
+        500 Mb/s for castagnoli on MacBook Pro (2.6Ghz I7) (5Gb/s for big chunks)
 
     [author:]
-	Stefan Vogel (stefan@zwerg)
+        Stefan Vogel (stefan@zwerg)
 
     [instance variables:]
 
     [class variables:]
 
     [see also:]
-	SHA1Stream
-	MD5Stream
+        SHA1Stream
+        MD5Stream
 
 "
 !
@@ -135,96 +135,114 @@
 "
 
   expect 60C1D0A0
-								[exBegin]
+                                                                [exBegin]
     self information:(CRC32Stream hashValueOf:'resume') hexPrintString
-								[exEnd]
+                                                                [exEnd]
 
   expect 16r60C1D0A0
-								[exBegin]
+                                                                [exBegin]
     self information:(CRC32Stream new
-			    nextPut:$r;
-			    nextPut:$e;
-			    nextPut:$s;
-			    nextPut:$u;
-			    nextPut:$m;
-			    nextPut:$e;
-			    hashValue) hexPrintString
-								[exEnd]
+                            nextPut:$r;
+                            nextPut:$e;
+                            nextPut:$s;
+                            nextPut:$u;
+                            nextPut:$m;
+                            nextPut:$e;
+                            hashValue) hexPrintString
+                                                                [exEnd]
 
   expect 16r70E46888:
-								[exBegin]
+                                                                [exBegin]
     self information:(CRC32Stream hashValueOf:#[1 2 3 4 5 6 7]) hexPrintString
-								[exEnd]
+                                                                [exEnd]
 
   expect 16r8CD04C73:
-								[exBegin]
+                                                                [exBegin]
     self information:((CRC32Stream hashValueOf:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
-	     16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
-	     16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
-	     16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString)
-								[exEnd]
+             16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
+             16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
+             16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString)
+                                                                [exEnd]
 
   timing throughput:
   230Mb/s (on MacBook Pro 2012 / 2.6Ghz I7)
-								[exBegin]
+                                                                [exBegin]
     |hashStream n t|
 
     hashStream := CRC32Stream new.
     n := 2000000.
     t := Time millisecondsToRun:[
-	    n timesRepeat:[
-		hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
-	    ].
-	 ].
+            n timesRepeat:[
+                hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
+            ].
+         ].
     t := (t / 1000) asFloat.
     Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString.
     Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
     Transcript show:(n*50/1024 / t); showCR:' Kb/s'
-								[exEnd]
+                                                                [exEnd]
 
   500Mb/s (on MacBook Pro 2012 / 2.6Ghz I7)
-								[exBegin]
+                                                                [exBegin]
     |hashStream n t|
 
     hashStream := CRC32Stream newCastagnoli.
     n := 2000000.
     t := Time millisecondsToRun:[
-	    n timesRepeat:[
-		hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
-	    ].
-	 ].
+            n timesRepeat:[
+                hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
+            ].
+         ].
     t := (t / 1000) asFloat.
     Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString.
     Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
     Transcript show:(n*50/1024 / t); showCR:' Kb/s'
-								[exEnd]
+                                                                [exEnd]
+  the real speed is shown with longer inputs...
+                                                                [exBegin]
+    |hashStream n t l s|
+
+    hashStream := CRC32Stream newCastagnoli.
+    n := 20000.
+    s := '1234567890' ,* 10000.
+    l := s size.
+    t := Time millisecondsToRun:[
+            n timesRepeat:[
+                hashStream nextPutAll:s
+            ].
+         ].
+    t := (t / 1000) asFloat.
+    Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString.
+    Transcript show:t; show:' seconds for '; show:(l*n/1024) asFloat; showCR:' Kb'.
+    Transcript show:(n*l/1024/1024 / t); showCR:' Mb/s'
+                                                                [exEnd]
 
   test vectors from https://tools.ietf.org/html/rfc3720#page-217:
 
   expect 0
-								[exBegin]
+                                                                [exBegin]
     self information:(CRC32Stream newCrc32c hashValueOf:'') hexPrintString
-								[exEnd]
+                                                                [exEnd]
   expect C1D04330
-								[exBegin]
+                                                                [exBegin]
     self information:(CRC32Stream newCrc32c hashValueOf:'a') hexPrintString
-								[exEnd]
+                                                                [exEnd]
   expect E3069283
-								[exBegin]
+                                                                [exBegin]
     self information:(CRC32Stream newCrc32c hashValueOf:'123456789') hexPrintString
-								[exEnd]
+                                                                [exEnd]
   expect 8A9136AA
-								[exBegin]
+                                                                [exBegin]
     self information:(CRC32Stream newCrc32c hashValueOf:(ByteArray new:32 withAll:0)) hexPrintString
-								[exEnd]
+                                                                [exEnd]
   expect 62a8ab43
-								[exBegin]
+                                                                [exBegin]
     self information:(CRC32Stream newCrc32c hashValueOf:(ByteArray new:32 withAll:16rFF)) hexPrintString
-								[exEnd]
+                                                                [exEnd]
   expect 46dd794e
-								[exBegin]
+                                                                [exBegin]
     self information:(CRC32Stream newCrc32c hashValueOf:(0 to:31) asByteArray) hexPrintString
-								[exEnd]
+                                                                [exEnd]
 
 "
 ! !
@@ -523,3 +541,4 @@
 version_CVS
     ^ '$Header$'
 ! !
+