1
- import time
1
+ import time , random
2
2
from ctypes import *
3
3
import mmap
4
4
@@ -27,10 +27,10 @@ def compile_asm(s,ftype):
27
27
#order: edi,esi,edx,ecx,r8d
28
28
#-Ofast -mavx -mavx2
29
29
30
+ random .seed (1 )
30
31
n = 100000
31
- a = [i % 100 for i in range (n )]
32
- a1 = (c_int * n )()
33
- for i in range (n ): a1 [i ]= a [i ]
32
+ a = [randint (0 ,1000 ) for i in range (n )]
33
+ a1 = (c_int * n )(* a )
34
34
n1 = c_int (n )
35
35
d = 7
36
36
d1 = c_int (d )
@@ -56,7 +56,7 @@ def compile_asm(s,ftype):
56
56
#t=sum(a)
57
57
t = asm_sum (a1 ,n1 )
58
58
#print(t)
59
- print ('time sum=' ,time .time ()- t1 ) #4633 vs 446ms
59
+ print ('time sum=' ,time .time ()- t1 ) #7726ms vs 647ms
60
60
61
61
62
62
#sum parallel 4
@@ -79,7 +79,7 @@ def compile_asm(s,ftype):
79
79
3a: 44 01 d0 add eax,r10d
80
80
3d: 44 01 d8 add eax,r11d
81
81
40: c3 ret
82
- ''' ,CFUNCTYPE (c_int ,POINTER (c_int ),c_int )) #189ms
82
+ ''' ,CFUNCTYPE (c_int ,POINTER (c_int ),c_int )) #223ms
83
83
84
84
85
85
#sum -Ofast
@@ -141,7 +141,7 @@ def compile_asm(s,ftype):
141
141
8f: 31 d2 xor edx,edx
142
142
91: 31 c0 xor eax,eax
143
143
93: eb c8 jmp 5d <L3>
144
- ''' ,CFUNCTYPE (c_int ,POINTER (c_int ),c_int )) #129ms
144
+ ''' ,CFUNCTYPE (c_int ,POINTER (c_int ),c_int )) #169ms
145
145
146
146
147
147
#sum -Ofast -mavx -mavx2
@@ -218,7 +218,7 @@ def compile_asm(s,ftype):
218
218
c9: 31 c9 xor ecx,ecx
219
219
cb: 31 c0 xor eax,eax
220
220
cd: eb 9b jmp 6a <L3>
221
- ''' ,CFUNCTYPE (c_int ,POINTER (c_int ),c_int )) #59ms
221
+ ''' ,CFUNCTYPE (c_int ,POINTER (c_int ),c_int )) #98ms
222
222
223
223
224
224
#sum x//d where x in a
0 commit comments