[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] vector type: mutable or immutable





Lorenz Quack schrieb:
Hi again,

I just did a quick performance test.
The first run uses an in-place operation (as could be used with mutable types) the second run on the other hand uses the equivalent expression without the in-place operator (as would be necessary if we go with immutable types).
Hi Lorenz,

I'd propose not to confuse two things:
(1) use of syntax x = x + x versus x += x
(2) use of immutable versus mutable datatypes

In python you can write

>>> a = 2
>>> a = a + a
>>> a
4

as well as

>>> a += a
>>> a
8

although the int type is immutable.

here are the calls with the results:

>>> timeit.repeat("x += x", "from vector import Vector2d; x = Vector2d(2, 3)", repeat=5, number=10000000)
[1.4092800617218018,
 1.4093708992004395,
 1.4093561172485352,
 1.413952112197876,
 1.4092509746551514]
Can you explain a bit how you implemented this. Seems miraculous to me as
even for plain integers I get:

>>> timeit.repeat("x += x", "x = 2", number=1000)
[0.00030635119219368789, 0.00030155776880746998, 0.000303348264651504]
>>> timeit.repeat("x += x", "x = 2", number=10000)
[0.023589079352177578, 0.023484539926357684, 0.023433343760189018]
>>> timeit.repeat("x += x", "x = 2", number=100000)
[2.1454171779987519, 2.1408996934512743, 2.1383358762293483]

highly nonlinear, which seems to have its cause in

>>> x
199800418602876901588806552866006718196085827810836338354305854772629166492851469665497466266489930080632878889111170986003759932153123531258169427084949857503977792597473421864927008547462249585316005570624821774741712105744567803291373820537013518470358293941057152893936030496646909510865005855730416139155419434822044640859527024106615559937958502332397415435715519110434401626405904092358984585185912478419315957471163173350509915946262896124985205236758826101611653720630702683574792456699817727155161242092132727442611755906446899440216169727390828036717027197160712071480437458163111331612143729225379456795892436845351586992777867144951775239182753135248222500414174097409303587927974202184007278694912361812032267557971205937271971160495228978660941044457202627541919167146389717969928091447677503414044846652668737888465947637554663065738884358722506038157378072073265663230054522798683056081423438298478066837498707889117926025843945128354344670870895031047586217845363648049055115041894092843718877257312654884626641694844431029866300054355001284576524236450986992011149146699293569665383619037919115383490193464488354808656809117642182758107512935442799532435705301143397096691249750366447665006372910109442287398683359633563405102456259561303896125908106783093149598825949983806970150886728290112633147920133867648546328680791602425605219684244950284156694244496628206081372074392803237114833128789445069298904994006290197801863245379054888574109528509445063350290423644629107767486164652844012660502750662587303286834504125123106235894772382858095228913098542568363503670626541059509907411228764791464558793460602121549136969548556643906984559676728723275294859390918133447382482726518642466712862717889304382037642476594818158327720464709019187775334728064591559878023043088960072744301382311822239920030611782154588420644608485240713869864321058551392517168916447091892905538462163946116125606530334728986875234648195066846665794605659183471385460265728466235192104609903433540663274190445139049208042867753103952880330562960446966637621951188439209529587770403970820346979718970220109384932344682862706198768118465379071730777739488540172140572710041711240590987049601015930431298393665302134882019356459039083232354350859950400197746147557524213717815419388232208760572479008906475791837415205785207869796522015497753457058362129369782877872981295691824232243866014158010741180843760257131188073981417760659337432233119224646639966218464501657323606437608788951459735241938716395687718559385002466538703893864154486710547311324964475756677761499985536632668806372089272374075795686260656876469408218886131829438566823819503704784246553487699811231273768658780788840052350619537012102658742028981727922832411121070946711398534018827505436582848144685358751301395311349518682026204506856601608181591746590884271026146041003431968484615209384194658145802832127079217611184047147537712957044801855542229782689848339912143435725968730679563617389482135022227070474230808731986217793949713176017757239498687158584924081035344920245012368080239325797453476061409967224359489693582014956927123893296584494722682302711343585835639361121074529682822566957164825182439092023688248186995659266340840050608373233899246374717213049708204444237390884475765783794241610291502827239296107394463291411299969590753143490962571948121546783175506647104312188718385503987020284444939260340274348386750098385907265902022305859036725656383836433033529118930316560979685122334963007356105357573254339992985938987540915897522932562218599640414740266606489020107707571023776069482963973302291586453698019860004734723371105883468841198507439304899958509663186874126879407436192229406461483739700701094445780543497006667366566005622658216833863009147798663678691865859898855920306195122374178378590568981484865695340124863423432454635332135922039356044091291780317990494094820023162219272674626587767137378988175186683538187756127971692946011778563519976889549722601263061375201401696745350555795547136600855578055442113676660429405594571906726642211281285278194491598993723258160392082835078715377531759848570998243034758485406864972968284949136777790837864829019750115188060264993950833939106605937604386097483270021958400724204775365503527399619552299592721934086962802482613671537598099948731925929914109190494707640007275406497899642066626658271246303397088208306341083878564694467976969071043464073761766242018878828698765644070993005630615021741972093624496059476512624899786639305924047452171730181006159866173040024633438303655314841913790262723681908242429475726220857954357228963166339316975338991096525050099224540894294244592405493647258196077549387539747178842508835847105967749596609005078195774669394652061950883129496109474654655344973055180699906727082539078009177099773671498557292305040816009802295717845781708867079939895617349432270395716771429128431663423860082359788815805366927151006797761734502557671545952529984276548731479858546044775851538484655709744025945107721439366075649661274517996169692770076567125168078346237453887629291073033801250600464351826861695104318029505982984305938887247338216664673875359862764185517400484924766624364734304735441968343754077203446170448960863526672055194663224025244966461706585779723091184428547570148219576444894590253271444511343395588195346830860345785366652701549024203357382426689313614795947454229238385998762363576550828435858537675805708618198848825210238916984758199326591005277314022297682845323259396201473054218570091589417230161881091555957286030097999172683294010564411255720177280514188648885080880684862804076241497150759980321329310419739615811786946404861012718147276430425612000836550586509704958558084714551971484191092647276618648565014230376035512674796230475239893725265411012701997025086677511892030818017240285872513474766633861646577086540029749532702376617703475505376390527203306918011123215354269072353109019488499581521278121866000568339296951880540933389369731872728508572504832896733043478451730569484899047266046106228268986646796446731032228629382638003409764536730518327994478252532322804114159934547670591949582509779228385745225195151234031852916470823038443545078393020686895873607381140076261131157326220229526263791431126730374555159838177257815309899040389498442977028341585047047885876034022989704780116887166594975385598831727692817545318034982098664777069308599585078011226231245764822943843162744202405347992972456632208605745374796806702842405990332216923863293761518890539304971401411089043050949869008697058359750243719472943809230308271651642780803442365914046550740547795755870138080898771071753010071143117457464031937701226622909542031513987508821949867482319823982299254536034360779018156060823688001511709371219539313391686512545666548328360891814556893601027215483085768254249127067672509381378728618041364335009196386434890267258277079663091212209193852090175754006083691583069565834515256212654442160716521218091449212384084751607262944003174981507232675704869245975398357756173429078576931448344470097755336077389069491776638151947105856014184829427413932940590614010141661828249855428095523869180146304124672684522562741490083250409468991948313577640076908935487779007583846891883424910204634779900606968438741761666594182163531220214173863160413901201928567040932946667223269533282126224941303476050211988185338179680933265972272977097424613198071315446553353921143741145536287898651187427360587519492082321512831998388045335884613629714467227271858073536829607166561862550136022231432301255231132143164732245370885366605494516985897517041795817019256704710559569829511274886369679869492666006619449940256168318019389103807516998915007589300383320197230055892122615894537970156992206077696920708467843508990117523142606894008316461604515733866010242536636920190204070863486475665843537319521525508248437856162777457603516262185920403014926639591229762926668253497925137675687023569551853211544254685386567647694234921675644198792932246166879043391531621308475439637991476808606318619464301198027424367995251701108709190326801102981611312546609507250578538900404523262618048415900125178627356260104442814859295123881075643649056661940431084218592773860109200238543566055231270114314708113453050483518508727437269436725840243249133241872841492110016848986945796612390121551410575096905553613224367161322605829265778644814020877750700157039943183967801693091939923942767994469917274996131648787692300983680969716383871213342519360371497556391222086704768417468354867703714713262025855148185611736800236097099882989574737658987375732744053652143974153125728735075514191206994367948111310105388504367086026978215704690355910395150329694230918569320075091169709419894749875932316820808284797515266704035910372897132644031971126838685733378250443068926975824363192454890507446284383694775411933198843625508072273208770776584036204097018354355829705120524850596049846184591243541255400553185763169479896085101354618068400869832658271772892548306369370349251603618026289547172749730564425489013237673357470900742790711265206995564199848331182232041948749828647215757586620301048340948756471070124112340351443507741235023858394313207260566046876391698931886569209658639210302497342472092513078071303466457135164218750824453484476940933294672405856496681302756289507354953437644401967793640395684334480309825067208728756949595412673158108362670460216091199170947593717294178755833186804475910740905476988708822119677759394822861021388025421312570150740796466177356397365963428303704365429872262219279680438248966468478027851076234519083064188700059096152805839655314830280859133339063546080067174030074069948497957962178789060539537564631158763178579937375327352071581106455896455153182096256704394914480446951398293004812734609856665723037500982597469158617499989760973625016058092128924471391255359297978297398484038929170427103314197742367565808743487512505652122810692239747906693550018732514935312769192590437445255549469609824679303885627074501373215641533677251309745580760409735561999835087616315796416505111324699678664349829877299325682337797493300108294965291999455040067401690851850886023807980824635055439875355996951025588960258276840686463097762758650497743441987623914443262962033405497547583236619378746974403378898065993178650239930082193073492378297231989632640817838611544772607926237164266826742201927782276731937918294307418501479969233640928528945815779530511870102730939567292063676412391211570351230099453236352980606099642770694773924244692522280860712019340850940246347208994492465749051503023975436031714856587780513016519765509902217308494084366745280461560913633028410356148363921928030269235215887255392244562522372218255336297610019019277780657554216753021038001522561169479385175374758746133295027758844347093880423153511151379403374682086848930510451379486594323054851162210069900914378635048941408206155216607310734283607774472058977456111815054222311815895138538079570392038795806235361407136038898722137012811370385812900973710712565135744514690882931310823756334354597012257480892417814370042170360501058491807196282350454406411052851955039688214849843584840781600292124519988442194343522374936916053474496027312077338199421426945117194464340551081101701641808379750696584440083579969500610390743581240030186660460477636130383648111016373443294234046150598453044560676408082267732506716300858682302879618799728327312678472413477485186854268894024854054444543951464063889788157127110232792382319718159907981673602589376215431918761698162225038760328297325002821905733618296570062478779219953183519546308655943478915251207300471758631198523417046301484956996285131293860162101239527947911834670909458350534791975802349548984354915438163389790875806291563053347793788212091767028900522612912744753752622599291533989515346813471670744374098703546404295588079451330651634633184043995058856488655562042150643211602088642421344165477522015566648531392495312421262539509830924486879561225079986277878315640171200223426395468862608259964312539701977914455563190490112808710699597117444690439835568391282132442440980780357734759958105411046048240055617294525650350501846651107574755848698318523654723024851844854517453996880282651359092809514849022522057147883869594327663742767414455648452387680420217925425633714645755284205974177911142967954869948362196992672678207955565084503588000442869717724150642452932272289750374702849889391516734895700560263860678038994774323262276017281868170585954594829256722844022411460548546191333176997699302685903765758740322949990093703702337034195162933739884873462800739847624649678412372573260748047026678155438149104484970314974522721500960419219531357240504647125460511141087734583785111433447937439833393036694739748805918847904417269626829680596778789711866545132546363882754709037830887699219329025711229535451298650338476440064594669666634526124001183841348822738264874408071561973528817893447346690998078105673648228440237738985306490627986475282011279934885473872131737024878734743106993927179409414124934861293630230511615447342587173830933543585613492063948873204713296238223506484795845432064278653818008628671450238711835715748778638216734444394991887704353656344110748679758787448413968451720040534044090046829688644628363196742664469346763719914404304259981337106371875303762456312886996857956080889485063463743964997604381122495136701062438733681822272269034807608000825629490549073750602454824525850988620169177361652543386257828284749339464313766139251925956485736569595163967646806904454175146907877942538203496703599426418458234928709100478532587709114852616809464919787486156737517281758286246384566146099507249634171596997411006287147373209070081993593707796051569558208384621050102893937704974526887307389078427443894319963132489086611255965655546991693335140379398019702203289820959872058459232902659904485428098163738961616362895308829521416698863598426953864115509874551622935989556396140898196617756048367090561911525363564431928214244330199903939238647375339198486738780373516609559026971299349932860139570962417220260580529652808046332420365172083454690039416771404455303771807862472544904640130719678152082557960152564415824923264454261038133560592885464575269201205784266321881147920070472162989757115696398472080674184878417915702019073324910760942368396681371798978680530362654839034982503851374596497559658767034204487797736695111244364297321510372568410168824817101768169988104530970715533577288893610086025719769398310033852423460991005367309966812758866831695947813339465436351342222468904254022765754663414072976871213850700257154912743320258556923882715129830165386460201271181759836629603592133297872137297511383094017212054078192801810292187210260745619699799529458684119421522087314133407392734621732335461287226663683286642081469584215513774075083864822035289761433466083525360690562558934584889058383237641906718913343169018829526030740651762185098432412048479967678792791417285366311154758470856609543381077014438798545336611344548858275053604743563518168745395614161993803853900051848420409703879076103103173265328364609042587420936804376133303304628771949961632428402961027102637309060297425964998772485443086907447836044302522317097239507979662217763927177511315871866211957919841064808793691817243864640304645153379390188307967874426174944954658889861075151553887253606566321101207064393700024143903833428521267281123580124373432092773684981344951457115281432627956492783773875792704954164643918808009016591877073030352850202586718229566759913170035323515708599336748344956776772917846398400823927818507084521483988243639003925031962741529341700449584032983481135899880499351860062599141994840531915707800213378517294376780521168351647929942190458894597483665479045844951843138873913640749554620990282576368624206349532010146572260913962837534774116711793611376241258033447794152060790994165468369681380744303597245331638591108415113913082799536284700549811893251855419720891775873511242874192974114893306396295457843545818755996699055399902901223144087882573742430775136851360732446427390160838314749380198340960797718945209725173688995247246374481706790004099785919272374788748178377771378073822579756646517852026623105218022638239250730587692879869313329805422170456689403695367831472477904794655623167987103560441523549015118582767629370531546183045810050182904822680137913221475226409690912910872204775461751886168173995654226308510269441178786789060270962704883535082627700255400483125238723392994198883138670833331818715195695518929379078470324594473468073016117723724197762473541977858895393087206493377488594802607300195405832070728530056892360922562746480120698957794154465247298550310900274635945552305444720171931974733876829353700603322070339767819911413186634264391480065020926072083925905526339457879818901825590907232551869736369116603372685613064100574582100538132874523413235568786223094742995181922322889876242134920745029052325432304258700862822483116996951481837569168203546500611064144753238679405089766708701382271555155311691022734292692584462289956190928101580535117083219085211155668129347123787970063206060933750451594167759865975383659736459413347124932958793067309090885367728086453005920577625971144843963744160804145921549922577723335465776772412199558508336443134274073347826666441730417438089460971860349335871563476616648129191700363545348953807530463574802852730043441862052385260930842254161895393647844147675949641140695863930502784427403997550878623572024763978494140952591750030325998257858661380506871509765029098969386566457964059130138066169409650354882623329295495014469557230361106869337160819742645469061636735891287288603104925483162014621386461614698031810340175073083392019978231391969094058532587480987873553705714460795093823620429385344386676931261073476930756499400990124188070132124891688252558047684855705611031985063765255725430639791343307967708578186231542448772362394499712884678151176251497184353742994426836666345794299553899642344546753397567224255769305786989413539902935716719101482431367500658756447047573302065338468997753812395882331498728366958296479679760041352999345784299669728489374754845728771261288504469224212799048362923322227831728161794808278917596980733653909763956175320439199296935422913963187351358095362240941114812047024749980245171347159302140265031244756875099894944737676421212919389601346320647627023850702966444335228848222893907223656775222315918226207248414830216526440967490808082939809592941462268567366003164947014258446622395780263594033035280660732992134990372573136720651127064112347732054986548355990484877997611626452413625958712316424054729110808288574117142636704779034849424781015178387069811405366056256214095012063634185488696130096868442683044031592535527872853963377029710904137956040725149920871683614710461848205295888728479029497117079605187340344111775359706199420865808097689350834038378245514915048042434897806533623212956759700092797283872915841642105321150078423906229151852428016613206035362403571206573004403428276232843119734052750623111096439167778107870891843611745448674997984840830856333336436927497266750454581559884179210905297277250328234360982258069027562800430137999335241614653027608555849218615245268939883183864462851300599928062687671281755333790755197149468062409541837731927111598892873764119624840809556058876078649194444150834791791933840681043233616751778432720971695798593278062146998913340556612209662617257453613220306014910433397877147675653819500521573824901541933947114899421277567581672171266495480228532091775954256866701786835042416862670983116118904350075334562736379794021515900699518622942277023550581694167652938618873276757029775974473775430695406669131405080099280799755214919025522918733893910177555926368001864599474735410370251464664602542684218741373619005287244510217457542832712034325525340803379936325744266528445367557106557756446204090795245451660298052194218623899913719016691970185176067260391037836924259818298403116765972151363814747519171466965234275894071850079442526286323843191429021634880682296958087732025684892867257147848846335348220728351155539837734398210229138040058115433983549954967189796202313011145070024850391918629668808342324444110091793432735089560857869767710005504229950524928422440215497246669524923651531943568079608732353391211340998735787007417863492351205641493581162216125606977862735375462664694423570820765784261611607386057078207694090560366881166265054882598567114654080564418039031201088995292718641301675217289479793854187622410085025338616696799999137204327122978803348851281569387003054604914988714444100188073616206422737978928861240833197567208136226624342670099210098883309457678527572157367714630307327468326251322452064719554849478806495869574815407054508730649106168765017313877286600419142414382456533784752185470489351532959635952456634184963742863789488998566581021741337325278029255092003733671672441248911076577342872428315472764897051413293068460040067721743713667741905651284637846746116549356502058104784289282351814001657257498312944259244462002996855478211705254241914052668502781385510824998516537975118260969781181673300947731380119614530253652876196001615374337794995340114944565703308618709388474025938024504000835519505561986827982989113513108315825780282836143619416360213372520006694935669842327086614835331123957308258886631592217134678144219416304953887204164621547546385118711838387230199844837037395250236439431968987928458464451738791664116990752003467764858336265140063969818856103570575656851200430984664700658837456852022192468641229710951580776056984562787942619583611248954069885990611718188300624748004268908632140990776182357411420913724232421393100460577732341206291604457686898137588097814881343291151303211927949763294891508188017838221678902524679809067295450834826626616423075179661547808050994795032416516757967699924017494992446628727091071994209457927925258293510845634712493316084240145508025479645393036051922606686595857306601273083513520067393764878527825614262460775201520799145713166667816771850684986743061409149429654871020748342940480137348382837487964608984055440193645649492816055581362094832057652268816065132150604603440639621415937861039082904786553235678116578878642922977896433918371589970045277166374089465805995809463875076070878405714127013449684900178413794259906164274946705115859651316069395590099481066590124411691739535647530947161853415077834733048031550517804047097664549613579226569336437319457395711853456536453129151559173411421954567932102030327743272306438364073054597951736155728860897932573407863769738438636783658543451090075354661537126173152013306852445090701152580617254378747286548961671178564402047499030693305257150084459019908920288576037181228867593582854348265565739519965199876381689549395504411357967907571403092183153900122573792216510387469732251364500211715047501009010072832556088133538102611296143820282645701269653314536570238661188674347477992473094310696331832601736770418109821203891935164474038230271622841430424413470438975541390432170634349551610851082760779577474321164835438085048021127413235859927916174134341677459004761144770952209901234653791758964806391389980011891874396980082091000688300281323090539892181888827828781437326180184993836249376261762524847175744097121792164680753548750189935369021161191599543780132107098067199235684902421922897541263749338205847132555423304070452940323325929761676179957753755386164417130601363078817134960826989389837414099853204201329116396657722613560429207397863489998782144624608101766849707675934844176941207706698878562950393715825843488838347727974783118178317186215008988399388517138410077825551001851200584511320564914661083287409659307030653915146239720663077235342541446459253402449612246443909777836960802987155142626046177950026971472007142686140932563143574400431574119666057128037028073483370471584046128812883188971731324938109559281731449252236681264260502524617938994272846691708387022567462643144642031553757682959735047288834225969447095262854317005868694928682544604514715841941668798209967880395799597407036755720215573344522044833689973727977484551612625451629487933534388088885801425698285725037341701847169065541828821991507153196243570475136978688593407373723624598560668669133929869215418071844636081456996552819117477089829108329612421972381808986635225779322706508261246279839429246655369744483682381776821096385417578978791813635571591778371757628521984835355077247648120049036422980703202489857878811569881108643471795590077355848972295388974693437271676345932541466828080552620596431246062843154867585892332987487231209180721205971624491521705054011401237552191654919499348106317643253919657022860126417954609462669223442858916108143577524460229251170210418615235429865572070825254397610456537282141100987287411116338916616813019208946437365337164338075697360645609597280434126313073749785809353580317294187589575247460276440527475776456551283274517453418432048681545585971313596504698928567523258374351139869093874495194892887491722471555376852946938487318191171063251431296159380681053430095215094853539200765116280687094330416691977290768651878163087858378781797922181670439850381070607967181630325784951420867095728499099614827774907720462266591827812720133890788748773815191782425775160156081658239504141905562666711004655535235667827635882102188259993608602077989501024864646628622413271974532372201694345093938174532749137169332923241864468553613692034370334048553422518261601191661073163600719824288953705730699707940277521616340418369457267027375674905025858725887462755955883363262619673776672491849765400850665506203480748037163103853262951760649006326996578881818829188714196786629081558752770677696481139291673238131607246241195200742553296619902517186204285804746121040017668314994488100577268050000574941104673770821371867780793247598275529714315441874993621114365555628593184885033334062202716412506330378138729253272267535673540031498191228899256564113816406600262425797460157104125618300717606681434924670222856761931013036365423556519282946845517716063249472965070177585525981496264853849234283390421370976365507232255739104328247665264923280692055421061044342548338196634288516855087186503874167358410497403724254171490630363941595952483126447392550606072500201148030063704835427634338339181331009609885349473933121036390554594808815649748327061741496068942526151009060375374690232625200051435314165882268943181166537189280459509781237371394310586506673583858090183626779780790624522281552082926827902405063981374413809013086347215987048695821640793909561238529065092881062491727240520323139157766528398206910394835842807921236349189346644227342261033516899414441612764986185706965154941655098797212170169727730998258244407837907586646436286899969173611145358311070504242278154467780759588549704186190092831992783921065920605854785493278124683801697644396000815087805014368603369617323140180441063165477148345358046203871321284873216681604055727845273049067910094124882179155820985978167941954316137140730557458656935439045497504026437132885684782330040115726281665332131289380470977309048739908563461087669630650503126232068778828812251993245299197575380074248248126101454260987221215550387035333687019581902249407554570540903633071125712433135239587659216745041695184063622287688080102292279806525467242923013357037601586551269728896074539265569516369069370191307307614476154735870524842910661776673594541483856777453709699547746133400151039315228631678822040849852462664855405416434200942743043358977449374823785196112478209742779500684067533466899781201042234556893410610426548506643794699577766158872521982511394827016788681235014257528904440791149103000388859924654786341829758102976256431657891598994972468669057309205498902669545346907255993694132218754153760967591357209997746545745463175703910104338939731435187457519690299881747334713993806444252381467442639699457474296478441127223165534385873750359019146295506954595601477409019384084028112832993409176981149335873643110438021900559320471804012591268532433951123325239134428068796072438364863544842209696478032442428664927890236643814740725527251138950707452388722539932906844591780134739040297407877300301741488294704404415408221401766560614630900821714435248972006491490592848916031017750711628902578363473726922331342221003022194295210887230758404150922301470583358707196074924663160708050145871708442699004793100096369125126555898608838525658827260144483015162889553779111392320514828477185488314809544352869498973263663652964201675714981604443982442893882348005417123181902097716919347846652046036874806574056171395646223649207852842580494583850704535751357957371292011410902178907483812987431177885066594069739653867732691496156021574385082595698143105533668107248144579500360328349733904532789377955996594940688296932104659550638285332769478136210833423361322625258376695296012793095246903850811608005154559017181236346520003767133551524992701690245328211151032902689405241669709615523474038472528127696627436841749544461889359573224432993796846455784975252103357973729514780245207221358493234567800325346881198064480530726871006031059665290397317626078851732354699745604637850885560322266367085522065160047878852157175138989702386014317078596863279351510627049684425496297280545946143109142188468649437139410472713445731030325313447784961613185588979061574163072133334826291965215976225575093126260155714869683792216189982388720751221506527188282869537649893850615755813865505817918198901305441439588393654836816396611349953761724729216386912472754049356301462669323958462398782343919587056662349936410011545998771329539685216310378817335526417109663196723777008966798227030102658194079801778381262667516081897739117909318252962090692428605914667519857979186593288893738012973490633237576425943882923838282659573467505674059903814123598483562804987125700130725475432727111394400064939922613305649033903345463236627877351175825565298675160800221184227445416782470369194182149613397053921618183637459570031481290890965289421572667731982263776202754926379689934919780230806685186306954801642214696369430425067490145430762620965932259581629553265395827891407147810748455395592676231367924464168051940503

which has more than 30000 digits. Which result did you get after 10000000 executions of the statement x = x + x?

And which implementation of the long integer type did you use that is that much faster than Python's ?

Regards,
Gregor


>>> timeit.repeat("x = x + x", "from vector import Vector2d; x = Vector2d(2, 3)", repeat=5, number=10000000)
[2.3679590225219727,
 2.3530960083007812,
 2.3615989685058594,
 2.3519301414489746,
 2.3658668994903564]

that is quite an overhead IMHO.
Of course it is quite possible you could tweak this a bit but I imagine the result would stay more or less the same.

Note that the vector type in this example was implemented as C extension.

This make me once more lean towards mutable.



Lorenz Quack wrote:
Hi,

I'm against implementing both. I think it makes what should be a rather simple class overcomplicated. Imagine the zoo of class we would have:
Vector2d, Vector2dConst, IntVector2d IntVectro2dConst, Vector3d, ...

I think we should make up our minds and then sick with one.

And I have to add that even though I started off favoring mutable vectors I then remembered also running into the subtle bugs Brian mentioned. So now I'm leaning in the immutable direction.



Brian Fisher wrote:
I guess making both would be the most pythonic - python gives you both lists and tuples...

On Fri, May 1, 2009 at 11:04 AM, Jake b <ninmonkeys@xxxxxxxxx <mailto:ninmonkeys@xxxxxxxxx>> wrote:

Could you make both? Default to mutable, and use VectorConst ( insert
    better name ) where needed.

           .offset = Vector3Const(1,2,3)
           .vel = Vector3( offset )

    (throw exception when you try to modify a const vector?)
    --
    Jake