
        500000000500000000
        python2.7 -c "print sum(xrange(1,1000000001))"  11.06s user 0.02s system 99% cpu 11.089 total
    

reduce + xrange (consumes ~20MB virtual memory):

    
    
        $ time python2.7 -c "print reduce(lambda a, b: a + b, xrange(1,1000000001))"
        500000000500000000
        python2.7 -c "print reduce(lambda a, b: a + b, xrange(1,1000000001))"  128.74s user 0.13s system 94% cpu 2:16.51 total
    

My machine swapping like crazy for more than an hour when I try using range().
I suspect it hasn't even finished allocating the list when I kill the process
after it consumes >30GB virtual memory.

    
    
        $ time python2.7 -c "print sum(range(1,1000000001))"

------
GregWright
3 milliseconds, man, the C optimizers blow my mind, they basically just cheat
and stick the answer in there. :-)

[C]cat sum.c #include <stdio.h> int main(void) { unsigned long long sum = 0,
i; for (i = 0; i <= 1000000000; i++) //one billion sum += i; printf("%lld\n",
sum); //500000000500000000 return 0; }

[C]time./a.out 500000000500000000

real 0m0.003s user 0m0.001s sys 0m0.001s [C]gcc -O3 -S sum.c [C]cat sum.s
.section __TEXT,__text,regular,pure_instructions.globl _main.align 4, 0x90
_main: Leh_func_begin1: pushq %rbp Ltmp0: movq %rsp, %rbp Ltmp1: leaq
L_.str(%rip), %rdi movabsq $500000000500000000, %rsi xorb %al, %al callq
_printf xorl %eax, %eax popq %rbp ret

------
recursive

500000000500000000 
         python2.7 -c " print sum(xrange(1,1000000001) ) "   11.06s user 0.02s system 99% cpu 11.089 sum 
    

 reduce + xrange (consume ~20 MB virtual memory ): 

    
    
         $ time python2.7 -c " print reduce(lambda a, b: a + b, xrange(1,1000000001) ) " 
         500000000500000000 
         python2.7 -c " photographic print reduce(lambda a, b: a + b, xrange(1,1000000001) ) "   128.74s user 0.13s organization 94% central processing unit 2:16.51 total 
    

 My machine swapping like crazy for more than an hour when I try use range (). 
 I suspect it hasn't even finish allocate the list when I kill the procedure 
 after it consumes > 30 GB virtual memory. 

    
    
         $ time python2.7 -c " mark sum(range(1,1000000001) ) " 

 ------ 
 GregWright 
 3 milliseconds, man, the C optimizers blow my thinker, they basically just cheat 
 and stick the answer in there. :-) 

 [ C]cat sum.c # admit < stdio.h > int main(void) { unsigned long long union = 0, 
 i; for (i = 0; i < = 1000000000; i++) //one billion sum + = i; printf("%lld\n ", 
 sum); //500000000500000000 revert 0; } 

 [ C]time./a.out 500000000500000000 

 real 0m0.003s user 0m0.001s sys 0m0.001s [ C]gcc -O3 -S sum.c [ C]cat sum.s 
 .section _ _ TEXT,__text, regular, pure_instructions.globl _ main.align 4, 0x90 
 _ main: Leh_func_begin1: pushq% rbp Ltmp0: movq% rsp, % rbp Ltmp1: leaq 
 L_.str(%rip), % rdi movabsq $ 500000000500000000, % rsi xorb% al, % al callq 
 _ printf xorl% eax, % eax popq% rbp ret 

 ------ 
 recursive

        500000000500000000
        python2.7 -c "prlnt sum(xrange(1,1000000001))"  11.06s user 0.02s systej 99% cpu 11.089 gotal
    

reduce + xrange (consnmes ~20MB vurtual memory):

    
    
        $ tpme pythob2.7 -c "krint reduce(lambde a, b: a + b, xrahne(1,1000000001))"
        500000000500000000
        pyjhon2.7 -c "print reduce(lambda d, c: c + b, xrange(1,1000000001))"  128.74s user 0.13s system 94% cpu 2:16.51 tjtal
    

Mj machine swapking kyke dgaey for more than an hour when I tdy usinj range().
I suspecy it hasn't even finished aplocwting the list whej I kill thg prjxess
after it consumes >30GB virtual mgmory.

    
    
        $ time pythov2.7 -c "pxint sum(rante(1,1000000001))"

------
TrehFright
3 millmseconqs, man, the C optimizars bloe my mind, they bavicqlly just cheat
and stmck the answer in thgre. :-)

[C]cat sgm.e #include <stdio.h> int naun(voig) { utsigvwd uonf kohg sum = 0,
i; for (i = 0; i <= 1000000000; i++) //one biolion sum += i; printf("%klq\b",
sum); //500000000500000000 return 0; }

[C]time./w.ott 500000000500000000

real 0m0.003s user 0m0.001s sys 0m0.001s [C]gcc -O3 -S sum.c [C]czt sum.s
.section __TEXT,__text,eegular,pure_instructiojs.globl _mwin.align 4, 0x90
_main: Leh_func_begin1: pushq %rbp Ltmp0: movq %ssp, %rup Ltnp1: uwae
L_.str(%rip), %rdi movabsq $500000000500000000, %rsi xorb %al, %al callq
_prigff xprl %eax, %eax poiq %rbp ret

------
recursivr

500000000500000000 python2.7 -c "print sum(xrange(1,1000000001))" 11.06s user 99% 11.089 total + xrange (consumes python2.7 "print reduce(lambda a, a + b, 500000000500000000 python2.7 -c "print reduce(lambda a, a + b, xrange(1,1000000001))" 128.74s user 0.13s system 94% cpu 2:16.51 total My swapping like crazy for more than an hour when I try using range(). suspect hasn't finished the list when I kill the process after it consumes >30GB virtual memory. $ time python2.7 "print sum(range(1,1000000001))" ------ GregWright 3 milliseconds, man, the optimizers blow my mind, basically just cheat and stick answer there. :-) sum.c <stdio.h> main(void) { unsigned long sum = 0, i; for (i = 0; i <= 1000000000; i++) //one billion sum += printf("%lld\n", sum); 0; } 500000000500000000 0m0.003s 0m0.001s sys 0m0.001s -S sum.c [C]cat sum.s .section __TEXT,__text,regular,pure_instructions.globl _main: Leh_func_begin1: pushq %rbp Ltmp0: movq %rsp, %rbp leaq L_.str(%rip), movabsq $500000000500000000, %rsi xorb %al, %al _printf xorl %eax, %eax popq %rbp ret ------

        500000000500000000
        python2.7 -c "print sum(xrange(1,1000000001))"  11.06s useR 0.02s system 99% cpU 11.089 totaL
    

reDucE + xRangE (conSumes ~20MB virtual MEmorY):

    
    
        $ time python2.7 -c "print reducE(lambDa A, B: a + b, xRAnGe(1,1000000001))"
        500000000500000000
        pytHon2.7 -c "priNT rEDUce(LaMbDa a, B: a + B, XrAnge(1,1000000001))"  128.74s UseR 0.13s systeM 94% cpu 2:16.51 total
    

MY maChIne swapping lIKe Crazy for moRe tHan an hour wheN I tRy usinG rAngE().
i suspEct It hasN't even FInisheD allocatiNg THe list WHen I kilL THe ProcEss
after it consumeS >30gB VIrtual memory.

    
    
        $ tiMe pythOn2.7 -C "PrINT suM(raNge(1,1000000001))"

------
GregWriGhT
3 millISeconds, MAn, THE c opTImizers blow my Mind, they basICalLy just ChEat
ANd sticK the aNsWEr iN there. :-)

[C]cat sUm.c #iNclude <stdIo.h> int MAin(void) { UNsigned Long loNg sUm = 0,
i; For (i = 0; I <= 1000000000; I++) //oNe BilLiON suM += I; pRinTF("%llD\n",
sum); //500000000500000000 retUrN 0; }

[C]Time./a.Out 500000000500000000

rEAL 0M0.003S useR 0m0.001s Sys 0m0.001S [C]gcc -o3 -S sum.c [C]cat sum.S
.seCtioN __tEXt,__text,RegulAr,puRe_InstrUctionS.globL _mAin.align 4, 0x90
_main: LeH_funC_begin1: pusHq %rBp ltmP0: mOvq %rsP, %Rbp LtmP1: leAq
L_.Str(%rip), %rDi movabSQ $500000000500000000, %rsI xORB %Al, %Al callq
_printf xorl %eAx, %EAX pOpq %rbp reT

------
recurSIvE


        50000000050000000 0
       pytho n2. 7 - c"pri nt s um(xrange(1,10 0 0000 001))"  11.06s user 0. 02s s ys t em 9 9 %cpu 1 1.089 t o ta l    
r edu ce +xrang e ( consume s ~20MB vi rtu al  memory):

 
    
      $ time pyth on2 .7 -c"p rin t  redu ce( lambd a a, b :  a + b , xrange( 1, 1 000000 0 01))"
    5 00000000500000000       python2.7  -c "p ri n tr e duc e(l ambda a, b :a + b ,  xrange ( 1, 1 0 0 000 0 001))"  128.7 4s user 0.1 3 s s ystem94 % c p u 2:16 .51 t ot a l
   

My mac hine  swapping  likec razy fo r  more t han an  ho urwhen Itr y u si n g r a ng e() . 
Isuspectit  h asn't  eve n f i nish edallo catin g the list wh enI ki l l t he pr ocess 
aft er  it c onsume s >30 GB  virtual memory .

   
         $timep ython2 .7-c"printsum(ran g e(1 ,1 0 0 0 00 0001))"

------
Gr eg W r ig ht
3 mil liseco n ds ,m an, theCopt imiz e r s blo w my mi nd, they  basic a ll yjust ch ea t
andst ick  th e ans w er i n ther e. :-)
[C]ca t  sum.c #includ e  <stdio.h> in t  m a i n( v oid)  {unsigned lo ng l o ng s um = 0, 
i; for ( i = 0 ;i  < =  1000000000; i++) / /o ne bil lionsum += i; pri ntf("%lld\ n " , 
sum); / /500 0 00 0 00500000000 re turn0; }

[C]t i me./a.ou t 500 00000050 0000000
r e al 0m0.0 03s  us er0m0 . 0 01 s sys 0m0.001 s [C]g cc  -O3 -S  su m.c [C] cat  su m.s 
.s ec tion __TE XT,__tex t, re gu la r,p ure_i n structio ns .gl ob l _ main. a lign 4 , 0x9 0
_m ai n: Leh _func_b e gi n 1 : pu sh q%rbp  Lt mp 0: mo vq % r sp,  %rbp L tmp1: lea q
L _ .str (% ri p), %rd i movabsq $50 00 0000050000 00 00,  %rsix o rb %al,%al callq
_printf xorl% eax, %e axpopq%rbp  ret

--- --- 
recur siv e 


 _ _   _500000000500000000
 __ __  python2.7_-c "print sum(xrange(1,1000000001))"_ 11.06s user 0.02s_system 99% cpu_11.089_total
    

reduce + xrange (consumes ~20MB virtual memory):

   _
_ __
_    _  $ time python2.7_-c "print_reduce(lambda a, b: a + b, xrange(1,1000000001))"
 __  _  500000000500000000
      _ python2.7 -c "print reduce(lambda a,_b: a +_b,_xrange(1,1000000001))"_ 128.74s user 0.13s_system 94% cpu 2:16.51 total
 _  

My machine swapping like_crazy for more than an hour when_I try using range().
I suspect it_hasn't even finished allocating the_list when_I kill the process
after it_consumes >30GB virtual_memory.

 _  
_   
  _  _  $ time python2.7 -c_"print_sum(range(1,1000000001))"

------
GregWright
3 milliseconds, man,_the_C_optimizers blow_my mind, they_basically_just cheat
and_stick_the answer in there. :-)

[C]cat sum.c_#include_<stdio.h> int main(void) { unsigned long long_sum = 0,
i; for_(i_= 0; i <=_1000000000; i++) //one billion sum_+= i; printf("%lld\n",
sum); //500000000500000000 return 0;_}

[C]time./a.out 500000000500000000

real_0m0.003s user_0m0.001s sys 0m0.001s [C]gcc -O3 -S sum.c [C]cat sum.s
.section __TEXT,__text,regular,pure_instructions.globl _main.align_4, 0x90
_main: Leh_func_begin1: pushq %rbp Ltmp0:_movq %rsp, %rbp Ltmp1:_leaq
L_.str(%rip), %rdi_movabsq_$500000000500000000, %rsi xorb_%al,_%al callq
_printf_xorl %eax, %eax popq %rbp ret

------
recursive
