*** empty log message ***
authorClaus Gittinger <cg@exept.de>
Thu, 04 Feb 2016 13:41:17 +0100
changeset 19143 8096983985e5
parent 19141 7241f0129961
child 19144 2f3d50c4e256
*** empty log message ***
SHA1Stream.st
--- a/SHA1Stream.st	Thu Feb 04 02:20:54 2016 +0100
+++ b/SHA1Stream.st	Thu Feb 04 13:41:17 2016 +0100
@@ -85,9 +85,9 @@
 #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
 #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
 
-
-/* Hash a single 512-bit block. This is the core of the algorithm. */
-
+/*
+ * Hash a single 512-bit block. This is the core of the algorithm.
+ */
 static void
 #if USE_ANSI_C
 SHA1Transform (unsigned int32 state[5], unsigned char buffer[64])
@@ -147,9 +147,9 @@
     a = b = c = d = e = 0;
 }
 
-
-/* SHA1Init - Initialize new context */
-
+/*
+ * SHA1Init - Initialize new context
+ */
 void
 #if USE_ANSI_C
 SHA1Init(SHA1_CTX* context)
@@ -168,8 +168,9 @@
 }
 
 
-/* Run your data through this. */
-
+/*
+ * Run your data through this.
+ */
 void
 #if USE_ANSI_C
 SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int len)
@@ -198,8 +199,9 @@
 }
 
 
-/* Add padding and return the message digest. */
-
+/*
+ * Add padding and return the message digest.
+ */
 void
 #if USE_ANSI_C
 SHA1Final(unsigned char digest[20], SHA1_CTX* context)
@@ -406,6 +408,33 @@
     Transcript show:(n*50/1024 / t); showCR:' Kb/s'
 								[exEnd]
 "
+!
+
+performance
+"
+    CPU                             cc          algo        kb/sec
+
+    MAC (2010 macbook; 2.7Ghz I7)   clang -O2   slow        128495
+							    131967
+
+
+
+  timing throughput:
+								[exBegin]
+    |hashStream n t|
+
+    hashStream := SHA1Stream new.
+    n := 1000000.
+    t := Time millisecondsToRun:[
+	    n timesRepeat:[
+		hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
+	    ].
+	 ].
+    t := (t / 1000) asFloat.
+    Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
+    Transcript show:(n*50/1024 / t); showCR:' Kb/s'
+								[exEnd]
+"
 ! !
 
 !SHA1Stream class methodsFor:'initialization'!
@@ -528,59 +557,59 @@
        && __byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX)
        && __bothSmallInteger(count, start)
    ) {
-        SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
+	SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
 
-        len = __intVal(count);
-        offs = __intVal(start) - 1;
+	len = __intVal(count);
+	offs = __intVal(start) - 1;
 
-        if (__isExternalBytesLike(anObject)) {
-            OBJ sz;
+	if (__isExternalBytesLike(anObject)) {
+	    OBJ sz;
 
-            nInstBytes = 0;
-            extPtr = (char *)__externalBytesAddress(anObject);
-            if (extPtr == NULL) goto bad;
-            sz = __externalBytesSize(anObject);
-            if (__isSmallInteger(sz)) {
-                objSize = __intVal(sz);
-            } else {
-                objSize = 0; /* unknown */
-            }
-        } else {
-            OBJ oClass = __Class(anObject);
-            int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
+	    nInstBytes = 0;
+	    extPtr = (char *)__externalBytesAddress(anObject);
+	    if (extPtr == NULL) goto bad;
+	    sz = __externalBytesSize(anObject);
+	    if (__isSmallInteger(sz)) {
+		objSize = __intVal(sz);
+	    } else {
+		objSize = 0; /* unknown */
+	    }
+	} else {
+	    OBJ oClass = __Class(anObject);
+	    int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
 
-            nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
-            switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
-                case BYTEARRAY:
-                case WORDARRAY:
-                case LONGARRAY:
-                case SWORDARRAY:
-                case SLONGARRAY:
-                case FLOATARRAY:
-                    break;
-                case DOUBLEARRAY:
+	    nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+	    switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+		case BYTEARRAY:
+		case WORDARRAY:
+		case LONGARRAY:
+		case SWORDARRAY:
+		case SLONGARRAY:
+		case FLOATARRAY:
+		    break;
+		case DOUBLEARRAY:
 #ifdef __NEED_DOUBLE_ALIGN
-                    nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
+		    nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
 #endif
-                    break;
-                case LONGLONGARRAY:
-                case SLONGLONGARRAY:
+		    break;
+		case LONGLONGARRAY:
+		case SLONGLONGARRAY:
 #ifdef __NEED_LONGLONG_ALIGN
-                    nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
+		    nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
 #endif
-                    break;
-                default:
-                    goto bad;
-            }
-            // nInstBytes is the number of bytes occupied by pointer instance variables
-            // subtract from size and add to byte-pointer
-            objSize = __Size(anObject) - nInstBytes;
-            extPtr = (char *)anObject + nInstBytes;
-        }
-        if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
-            SHA1Update(ctx, extPtr+offs, (unsigned int)len);
-            RETURN (count);
-        }
+		    break;
+		default:
+		    goto bad;
+	    }
+	    // nInstBytes is the number of bytes occupied by pointer instance variables
+	    // subtract from size and add to byte-pointer
+	    objSize = __Size(anObject) - nInstBytes;
+	    extPtr = (char *)anObject + nInstBytes;
+	}
+	if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
+	    SHA1Update(ctx, extPtr+offs, (unsigned int)len);
+	    RETURN (count);
+	}
     }
 bad: ;
 %}.
@@ -591,11 +620,11 @@
 !SHA1Stream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.45 2014-02-12 15:25:24 stefan Exp $'
+    ^ '$Header$'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.45 2014-02-12 15:25:24 stefan Exp $'
+    ^ '$Header$'
 ! !