Click here to Skip to main content
15,900,258 members
Home / Discussions / C#
   

C#

 
AnswerRe: Application Domain Pin
Eddy Vluggen15-Jan-10 3:11
professionalEddy Vluggen15-Jan-10 3:11 
GeneralRe: Application Domain Pin
dataminers15-Jan-10 9:50
dataminers15-Jan-10 9:50 
GeneralRe: Application Domain Pin
Eddy Vluggen15-Jan-10 11:17
professionalEddy Vluggen15-Jan-10 11:17 
GeneralRe: Application Domain Pin
dataminers16-Jan-10 2:23
dataminers16-Jan-10 2:23 
GeneralRe: Application Domain Pin
Eddy Vluggen16-Jan-10 8:50
professionalEddy Vluggen16-Jan-10 8:50 
GeneralRe: Application Domain Pin
dataminers15-Jan-10 10:31
dataminers15-Jan-10 10:31 
QuestionCaching powers of 2 -- performance consideration Pin
Lutosław14-Jan-10 22:36
Lutosław14-Jan-10 22:36 
AnswerRe: BitVector performance question [modified] Pin
Covean14-Jan-10 23:00
Covean14-Jan-10 23:00 
return (ulong)1 << (i % BITS_IN_WORD);


1. Should not be that slow that you have to do this.
But if you need to access it very often or in "long" loops I would cache it, because 0,5kB aren't that amount of memory. Big Grin | :-D

Edit: After I took a deeper look I would say caching those values would be not faster than your function.
Thats because of the fact, that you have to do the modulo calculation (what consumes the most time in
part of code) also in the cached variant.

Here some pseudo asm that shows what I mean

CreateMask Version:
movzx  rax, bit
xor    rdx, rdx
div    64  // = BITS_IN_WORD
mov    cl, dl
movzx  rax, bit
shl    rax, cl

In this code div is the slowest instruction, all other intructions are very fast!

Cached Version: (I assumed that the cached items are seq. stored in the memory)
movzx  rax, bit
xor    rdx, rdx
div    64     // = BITS_IN_WORD
shl    rdx, 3 // *= 8 (rdx = offset of the entry in mem)
add    rdx, (pointer to the "table" in memory)
mov    rax, [rdx]


As you see there is no real difference between both!


2. You have build an 64 bit indexer to be not so limited but on the other hand you have limited your GetBit function only to be able to access 2147483648 bits!
So I would guess you should use public bool GetBit(long bit) instead of public bool GetBit(int bit).

Greetings
Covean

modified on Friday, January 15, 2010 5:47 AM

GeneralRe: BitVector performance question Pin
Lutosław14-Jan-10 23:55
Lutosław14-Jan-10 23:55 
GeneralRe: BitVector performance question Pin
Covean15-Jan-10 0:09
Covean15-Jan-10 0:09 
GeneralRe: BitVector performance question Pin
Lutosław15-Jan-10 0:33
Lutosław15-Jan-10 0:33 
JokeRe: BitVector performance question Pin
Covean15-Jan-10 0:54
Covean15-Jan-10 0:54 
GeneralRe: BitVector performance question Pin
Lutosław15-Jan-10 0:04
Lutosław15-Jan-10 0:04 
GeneralRe: BitVector performance question Pin
Lutosław15-Jan-10 0:09
Lutosław15-Jan-10 0:09 
GeneralRe: BitVector performance question Pin
Luc Pattyn15-Jan-10 1:47
sitebuilderLuc Pattyn15-Jan-10 1:47 
AnswerRe: Caching powers of 2 -- performance consideration Pin
harold aptroot15-Jan-10 4:38
harold aptroot15-Jan-10 4:38 
GeneralRe: Caching powers of 2 -- performance consideration Pin
Lutosław15-Jan-10 11:24
Lutosław15-Jan-10 11:24 
GeneralRe: Caching powers of 2 -- performance consideration Pin
harold aptroot15-Jan-10 11:51
harold aptroot15-Jan-10 11:51 
QuestionGenerate Color Book File Format (.acb file) for Photoshop using .NET or Other Language Pin
shaktisinh14-Jan-10 19:13
shaktisinh14-Jan-10 19:13 
Questionhow to inflate GDI+ Regoins Pin
VCsamir14-Jan-10 19:02
VCsamir14-Jan-10 19:02 
QuestionAny one having code to compare two xml files....? Pin
koolprasad200314-Jan-10 18:48
professionalkoolprasad200314-Jan-10 18:48 
AnswerRe: Any one having code to compare two xml files....? Pin
VCsamir14-Jan-10 18:56
VCsamir14-Jan-10 18:56 
GeneralRe: Any one having code to compare two xml files....? Pin
koolprasad200314-Jan-10 20:39
professionalkoolprasad200314-Jan-10 20:39 
GeneralRe: Any one having code to compare two xml files....? Pin
VCsamir14-Jan-10 21:17
VCsamir14-Jan-10 21:17 
GeneralRe: Any one having code to compare two xml files....? Pin
J4amieC14-Jan-10 21:31
J4amieC14-Jan-10 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.