[dba-VB] Merge rows

Shamil Salakhetdinov shamil at smsconsulting.spb.ru
Wed Sep 23 01:06:50 CDT 2009


Hi Stuart,

We're talking C#/VB.NET here? - try test code in P.S - 

===========
one billion
=========== 

of bitwise AND operations for 

============================
two 400 bits long bit arrays
============================ 

takes about

====================================
1 minute 4 seconds 260 milliseconds
====================================

on my "mere mortals PC" - two years old Dual Core Pentium.

Please correct me if you or anybody else here will find mistakes in my
coding/testing results.

Thank you.

--
Shamil

P.S.


static void test1()
{
    const long CYCLES_QTY = 1000000000; // 1 billion
    bool[] values1 = (bool[])Array.CreateInstance(typeof(bool), 400);
    bool[] values2 = (bool[])Array.CreateInstance(typeof(bool), 400);
    values1[0] = true;
    values1[225] = true;
    values1[399] = true;
    values2[225] = true;
    values2[399] = true;

    System.Collections.BitArray bitTest1 =
        new System.Collections.BitArray(values1);
    System.Collections.BitArray bitTest2 =
        new System.Collections.BitArray(values2);

    Console.WriteLine("{0:HH:mm:ss.fff}", DateTime.Now);
    for (long l = 1; l < CYCLES_QTY; l++)
        bitTest1.And(bitTest2);
    Console.WriteLine("{0:HH:mm:ss.fff}", DateTime.Now);

    foreach (bool bit in bitTest1)
        Console.Write("{0}", bit ? "1" : "0");

    Console.WriteLine();

//09:54:40.993
//09:55:44.733
//00000000000000000000000000000000000000000000000000000000000000000000000000
000000
//00000000000000000000000000000000000000000000000000000000000000000000000000
000000
//00000000000000000000000000000000000000000000000000000000000000000100000000
000000
//00000000000000000000000000000000000000000000000000000000000000000000000000
000000
//00000000000000000000000000000000000000000000000000000000000000000000000000
000001

}

static void test2()
{
    const long CYCLES_QTY = 1000000000; // 1 billion
    bool[] values1 = { true, false, false, true };
    bool[] values2 = { false, true, false, true };

    System.Collections.BitArray bitTest1 =
        new System.Collections.BitArray(values1);
    System.Collections.BitArray bitTest2 =
        new System.Collections.BitArray(values2);

    Console.WriteLine("{0:HH:mm:ss.fff}", DateTime.Now);
    for (long l = 1; l < CYCLES_QTY; l++)
        bitTest1.And(bitTest2);
    Console.WriteLine("{0:HH:mm:ss.fff}", DateTime.Now);

    foreach (bool bit in bitTest1)
        Console.Write("{0}", bit ? "1" : "0");

    Console.WriteLine();
    //09:52:32.604
    //09:52:46.785
    //0001
}


-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Wednesday, September 23, 2009 1:48 AM
To: Discussion concerning Visual Basic and related programming issues.
Subject: Re: [dba-VB] Merge rows

The data storage requirements may be smaller, but the time required to
perform multiple 
bitwise operation functions on every one of those 50 milllion rows is going
to be a lot slower 
than using simple selection criteria on fields.

-- 
Stuart


On 23 Sep 2009 at 0:15, Shamil Salakhetdinov wrote:

> OK, so you can "pack" 400 boolean fields into 50 bytes long binary field -
> that will be BINARY(50) in T-SQL.
> Although I'm not currently sure you can implement bitwise logical
operations
> solely using T-SQL: but I suppose you can get subset of data using
> non-Boolean where clause, and then scan it in C#/VB.NET and filter using
> bitwise C# operations/functions over bit arrays.
> 
> Something like that should work I suppose.
> 
> Please correct me if I'm wrong.
> 
> --
> Shamil  
<<< snip>>>
 

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4448 (20090922) __________

The message was checked by ESET NOD32 Antivirus.

http://www.esetnod32.ru
 




More information about the dba-VB mailing list