* No warranties and disclaimer of any damages.
* The latest sources: https://github.com/republib
*/
-/*
- * cuReMatcher.hpp
- *
- * License: Public domain
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * The latest sources: https://github.com/republib
- */
-
#include "base/rebase.hpp"
#include "math/remath.hpp"
class TestReMd5 : public ReTestUnit {
public:
- TestReMd5() : ReTestUnit("ReMatcher", __FILE__){
+ TestReMd5() : ReTestUnit("ReMD5", __FILE__){
run();
}
private:
void run(){
- testOld();
+ testSpeed();
+ testLong();
+ testBig();
+ //testOld();
testBase();
}
void testOld(){
checkEqu("d41d8cd98f00b204e9800998ecf8427e",
md5.hexDigest().str());
}
+ int testOneLong(ReByteBuffer& text, int seed2 = 0){
+ ReMD5 md5;
+ int rc = 0;
+ ReShiftRandom random;
+ random.setSeed(text.length() + seed2);
+
+ md5.update((uint8_t*) text.str(), text.length());
+ ReByteBuffer digest(md5.hexDigest());
+ md5.reset();
+ int max2 = text.length() / 20;
+ if (max2 < 1)
+ max2 = random.nextInt(20);
+ while(text.length() > 0){
+ int part = random.nextInt(32, 32 + 1 + max2);
+ if (part > text.length())
+ part = text.length();
+ md5.update((uint8_t*) text.str(), part);
+ text.remove(0, part);
+ rc++;
+ }
+ checkEqu(digest.str(), md5.hexDigest().str());
+ return rc;
+ }
+ void testLong(){
+ ReByteBuffer text("01234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ0123456789001234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ01234567890\n");
+ for (int ii = 178 - 69 + 1; ii > 0; ii--){
+ text.setLength(ii);
+ testOneLong(text, 200 * ii + 0x47111);
+ }
+ }
+ void testBig(){
+ ReByteBuffer text;
+ ReShiftRandom random;
+ int64_t start = timer();
+ int count = 1000;
+ int parts = 0;
+ int sumLength = 0;
+ for (int ii = 0; ii < count; ii++){
+ random.nextString(10, 20000, text);
+ sumLength += text.length();
+ parts += testOneLong(text, 333 * ii + 0x55221);
+ }
+ printf("count: %d updates: %d avg length: %d duration: %s\n",
+ count, parts, sumLength / count,
+ ReByteBuffer("").appendMilliSec(milliSecSince(start)).str());
+ }
+ void testSpeed(){
+ int max = 1024*1024*50;
+ ReByteBuffer buffer;
+ buffer.ensureSize(max);
+ buffer.setLength(max - 1);
+ buffer.fill('x', max - 1);
+ ReMD5 md5;
+ int passes = 2;
+ int64_t start = timer();
+ for (int ii = 0; ii < passes; ii++){
+ md5.reset();
+ md5.update((uint8_t*) buffer.str(), max - 1);
+ }
+ int duration = milliSecSince(start);
+ if (duration == 0)
+ duration = 1;
+ printf("size: %.3f MiByte count: %d rate: %.3f MiB/sec duration: %s\n",
+ max / 1024.0 / 1024, passes,
+ max / 1024.0 / 1024 * 1000 * passes / duration,
+ ReByteBuffer("").appendMilliSec(duration).str());
+ }
};
extern void testReMD5(void);
ReCongruentialGenerator rand;
const int MAX = 16;
time_t start = time(NULL);
- ReRandomizer::seed_t field[MAX];
+ int64_t field[MAX];
for (int ix = 0; ix < MAX; ix++)
field[ix] = rand.nextInt64();
rand.reset();
for (int ix = 0; ix < MAX; ix++){
- checkEqu(field[ix], rand.nextInt64(ix + 10));
+ int64_t current = rand.nextInt64();
+ if (field[ix] != current)
+ checkEqu(field[ix], current);
}
}
void testNextInt64(){
ReCongruentialGenerator rand;
const int MAX = 16;
time_t start = time(NULL);
- ReRandomizer::seed_t field[MAX];
+ int64_t field[MAX];
for (int ix = 0; ix < MAX; ix++)
field[ix] = rand.nextInt64(ix + 10);
rand.reset();
for (int ix = 0; ix < MAX; ix++){
checkEqu(field[ix], rand.nextInt64(ix + 10));
- checkT(field[ix] >= 0 && field[ix] < ix + 10);
+ if (! (field[ix] >= 0 && field[ix] <= ix + 10))
+ checkT(false);
}
time_t diff = time(NULL) - start;
}
#else
# error "missing __LITTLE_ENDIAN__ or __BIG_ENDIAN__"
#endif
-
//Initialize hash value for this chunk:
uint32_t A = m_a0;
uint32_t B = m_b0;
//Main loop:
int F, g;
-#define TRACE_MD5
+//#define TRACE_MD5
#if defined TRACE_MD5
printf("neu: (%s)\n", block);
#endif
for (int i = 0; i < 64; i++){
#if defined TRACE_MD5
+ if (i > 60)
printf("%2d: A: %08x B: %08x C: %08x D%08x\n", i, A, B, C, D);
#endif
if (i < 16){
g = (7*i) % 16;
}
#if defined TRACE_MD5
+ if (i > 60)
printf(" K[%2d]: %08x M[%2d]: %08x shift: %02d\n",
i, m_K[i], g, M[g], m_s[i]);
#endif
}
}
// process full 512 bit chunks (64 byte blocks):
- if (blockLength > 0){
- if (blockLength > 64){
- for (int ix = blockLength / 64; ix >= 0; ix--){
- processChunk(block);
- block += 64;
- }
- }
- blockLength %= 64;
- if (blockLength != 0){
- assert(m_lengthWaiting == 0);
- memcpy(m_waiting, block, blockLength);
- m_lengthWaiting = blockLength;
- }
+ for (int ix = blockLength / 64; ix > 0; ix--){
+ processChunk(block);
+ block += 64;
+ }
+ blockLength %= 64;
+ if (blockLength != 0){
+ assert(m_lengthWaiting == 0);
+ memcpy(m_waiting, block, blockLength);
+ m_lengthWaiting = blockLength;
}
}
*/\r
void ReDirOptions::checkStandardFilterOptions(){\r
ReByteBuffer buffer;\r
- checkDate(m_programArgs.getString("older", buffer));\r
- checkDate(m_programArgs.getString("younger", buffer));\r
- checkType(m_programArgs.getString("types", buffer));\r
- checkSize(m_programArgs.getString("maxsize", buffer));\r
- checkSize(m_programArgs.getString("minsize", buffer));\r
- checkPatternList(m_programArgs.getString("nodepattern", buffer)); \r
- checkPatternList(m_programArgs.getString("pathpattern", buffer));\r
+ if (m_programArgs.getString("older", buffer)[0] != '\0')\r
+ checkDate(buffer.str());\r
+ if (m_programArgs.getString("younger", buffer)[0] != '\0')\r
+ checkDate(buffer.str());\r
+ if (m_programArgs.getString("type", buffer)[0] != '\0')\r
+ checkType(buffer.str());\r
+ if (m_programArgs.getString("maxsize", buffer)[0] != '\0')\r
+ checkSize(buffer.str());\r
+ if (m_programArgs.getString("minsize", buffer)[0] != '\0')\r
+ checkSize(buffer.str());\r
+ if (m_programArgs.getString("nodepattern", buffer)[0] != '\0')\r
+ checkPatternList(buffer.str());\r
+ if (m_programArgs.getString("pathpattern", buffer)[0] != '\0')\r
+ checkPatternList(buffer.str());\r
if (m_programArgs.getString("verbose", buffer)[0] != '\0'){\r
unsigned level = V_NORMAL;\r
if (ReStringUtils::lengthOfUnsigned(buffer.str(), -1, &level)\r