Hello. I am developing a method that uses a compact representation of bitwise arrays instead of using boolean or even float vectors. One of the advantages, besides compression, is the xor operation that operates efficiently in the cpu architecture. However, using julia, I have some questions regarding performance and how to improve. I will leave here some observations and below the code with the times:

1). * Operation between a vector and a float matrix is more efficient than an x operation with a bit vector and a bit matrix

2) an operation * between two float arrays is more efficient than an operation xor a bit array and a bit array

3) To speed up xor operation between a bit vector and a bit array, it is best to replicate the array size vector and do the operation. However, replication wastes time and memory.

These issues are making it impossible for me to do coding and operation by bit arrays. Although more compact, it gets slower orders of magnitude.

Code:

‘’’

using BenchmarkTools

using Random

rng = MersenneTwister(1234)

vetbit = bitrand(rng,1,64) # 1 x 64

vetmatbit = repeat(vetbit,6400,1) # 6400 x 64

matbit = bitrand(rng,6400,64) # 6400 x 64

vetbool = rand(rng,Bool,1,64) # 1 x 64

vetmatbool = repeat(vetbool,6400,1) # 6400 x 64

matbool = rand(rng,Bool,6400,64) # 6400 x 64

matfloat = rand(rng,Float32,6400,64) # 6400x64

vetfloat = rand(rng,Float32,1,64) # 1x64

mat2float = rand(rng,Float32,64,64) # 1x64

println(“**xor and bitarrays**********”)

println(“vetbit xor matbit time:”)

@btime vetbit .⊻ matbit #res: 6400 x 64

println(“matbit xor matbit time:”)

@btime vetmatbit .⊻ matbit #res: 6400 x 64

println(“

**********”)**

**xor and boolarrays**println(“vetbool xor matbool time:”)

@btime vetbool .⊻ matbool #res: 6400 x 64

println(“matbool xor matbool time:”)

@btime vetmatbool .⊻ matbool #res: 6400 x 64

println("************ .* and float32 arrays********************")

println(“vetfloat .* matfloat:”)

@btime vetfloat .* matfloat #res: 6400 x 64

println("************ * and float32 arrays********************")

println(“matfloat * mat2float:”)

@btime matfloat * mat2float #res: 6400 x 64

‘’’

Execution times:

**xor and bitarrays**********

vetbit xor matbit time:

1.196 ms (6 allocations: 54.36 KiB)

matbit xor matbit time:

4.603 μs (5 allocations: 50.17 KiB)

************

**xor and boolarrays**vetbool xor matbool time:

526.435 μs (6 allocations: 54.36 KiB)

matbool xor matbool time:

408.657 μs (6 allocations: 54.36 KiB)

************ .* and float32 arrays********************

vetfloat .* matfloat:

161.289 μs (4 allocations: 1.56 MiB)

************ * and float32 arrays********************

matfloat * mat2float:

475.677 μs (2 allocations: 1.56 MiB)