# Why Dot product of my vectors takes longer than usual?

I have a list containing 100 complex numbers lying between 1.9 + 1.9 i and 2.0 + 2.0 i you can download its mx file from the link below and import it in Mathematica:

Now if you perform a simple calculation with this imported list:

vec = Import["vec.mx"];
c = Table[1.0 + 2.0 I + n (0.01 - 0.01 I), {n, 1, 100}];
AbsoluteTiming[Do[vec.c, 1000]]


It takes 0.0070265 seconds on my laptop. but a similar calculation with a randomly created list, takes half time:

randomVec = RandomComplex[{1.9 + 1.9 I, 2.0 + 2.0 I}, 100];
AbsoluteTiming[Do[randomVec.c, 1000]]


This one takes 0.0036907 seconds.

Could anyone help me what is the problem with my vec?

• Very strange, I observe the contrary. MMA12.1 on Windows 10. I increased the loop to 100'000 and get nearly 10 times faster evaluation time with your data:AbsoluteTiming[Do[vec.c, 100000]] -> {0.017462, Null}, AbsoluteTiming[Do[randomVec.c, 100000]] -> {0.140501, Null} If I may speculate, perhaps you data has some structure that can be exploited? – Daniel Huber Oct 26 at 10:02
• Please keep in mind that .mx is not a good format for sharing data. There's no guarantee that someone else can import it, since it's a system-dependent format. – Sjoerd Smit Oct 26 at 11:25

vec array is not packed, search questions related to PackedArray

vec = Import["vec.mx"];
DeveloperPackedArrayQ[vec]
c = Table[1.0 + 2.0 I + n (0.01 - 0.01 I), {n, 1, 100}];
RepeatedTiming[Do[vec.c, 1000]]

vec = DeveloperToPackedArray[vec] ;
DeveloperPackedArrayQ[vec]
c = Table[1.0 + 2.0 I + n (0.01 - 0.01 I), {n, 1, 100}];
RepeatedTiming[Do[vec.c, 1000]]
(* False *)
(* {0.00380565873015873073.,Null} *)
(* True *)
(* \
{0.0023348952380952382.,Null} *)
`