Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- y = x / 2.0;
- // or...
- y = x * 0.5;
- time python -c 'for i in xrange(int(1e8)): t=12341234234.234 / 2.0'
- real 0m26.676s
- user 0m25.154s
- sys 0m0.076s
- time python -c 'for i in xrange(int(1e8)): t=12341234234.234 * 0.5'
- real 0m17.932s
- user 0m16.481s
- sys 0m0.048s
- time lua -e 'for i=1,1e8 do t=12341234234.234 / 2.0 end'
- real 0m7.956s
- user 0m7.332s
- sys 0m0.032s
- time lua -e 'for i=1,1e8 do t=12341234234.234 * 0.5 end'
- real 0m7.997s
- user 0m7.516s
- sys 0m0.036s
- time luajit -O -e 'for i=1,1e8 do t=12341234234.234 / 2.0 end'
- real 0m1.921s
- user 0m1.668s
- sys 0m0.004s
- time luajit -O -e 'for i=1,1e8 do t=12341234234.234 * 0.5 end'
- real 0m1.843s
- user 0m1.676s
- sys 0m0.000s
- y = x / 3.0;
- y = x * 0.333333; // how many 3's should there be, and how will the compiler round?
- int main() {
- volatile int a;
- volatile int b;
- asm("## 5/2n");
- a = 5;
- a = a / 2;
- asm("## 5*0.5");
- b = 5;
- b = b * 0.5;
- asm("## done");
- return a + b;
- }
- movl $5, -4(%ebp)
- movl -4(%ebp), %eax
- movl %eax, %edx
- shrl $31, %edx
- addl %edx, %eax
- sarl %eax
- movl %eax, -4(%ebp)
- movl $5, -8(%ebp)
- movl -8(%ebp), %eax
- pushl %eax
- fildl (%esp)
- leal 4(%esp), %esp
- fmuls LC0
- fnstcw -10(%ebp)
- movzwl -10(%ebp), %eax
- orw $3072, %ax
- movw %ax, -12(%ebp)
- fldcw -12(%ebp)
- fistpl -16(%ebp)
- fldcw -10(%ebp)
- movl -16(%ebp), %eax
- movl %eax, -8(%ebp)
- flds LC0
- fstl -8(%ebp)
- fldl -8(%ebp)
- flds LC1
- fmul %st, %st(1)
- fxch %st(1)
- fstpl -8(%ebp)
- fxch %st(1)
- fstpl -16(%ebp)
- fldl -16(%ebp)
- fmulp %st, %st(1)
- fstpl -16(%ebp)
- ## 5/2
- ## 5*0.5
- ## done
- movl $5, %eax
- leave
- ret
- int y = 10;
- y = y >> 1;
- Console.WriteLine("value halved: " + y);
- y = y << 1;
- Console.WriteLine("now value doubled: " + y);
- >>> for i in range(7):
- ... a=1/(10.0**i)
- ... b=(1/10.0)**i
- ... print i, a, b, a-b
- ...
- 0 1.0 1.0 0.0
- 1 0.1 0.1 0.0
- 2 0.01 0.01 -1.73472347598e-18
- 3 0.001 0.001 -2.16840434497e-19
- 4 0.0001 0.0001 -1.35525271561e-20
- 5 1e-05 1e-05 -1.69406589451e-21
- 6 1e-06 1e-06 -4.23516473627e-22
- y = x * (1.0 / 2.0);
- public void Mutiplication()
- {
- float a = 1.0f;
- for(int i=0; i<1000000; i++)
- {
- a *= 0.5f;
- }
- }
- public void Division()
- {
- float a = 1.0f;
- for(int i=0; i<1000000; i++)
- {
- a /= 2.0f;
- }
- }
- Multiplications(): time/call: 1524.375 ms
- Division(): time/call: 1220.003 ms
Add Comment
Please, Sign In to add comment