Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

callCC oddness

Name: dddddddddddddddddddddddd 2007-03-31 15:40 ID:HM1BiqY2

for some reason

fac n = (`runCont` id) $
          callCC $ \k -> do
            when (n == 1) $ k 1
            return $ n * fac (n - 1)


is faster and uses less memory (for n=10000) than

fac' = product . enumFromTo 1

or [code]fac'' n = foldr1 (*) [1..n]

what gives /prog/?

Name: Anonymous 2007-03-31 15:41 ID:HM1BiqY2

ps. yes I realise product == foldr1 (*)

Name: Anonymous 2007-03-31 16:15 ID:TMGtAGig

Name: Anonymous 2007-03-31 16:24 ID:HM1BiqY2

>>3
actually it makes no difference if you fold left or right in this case.

Name: Anonymous 2007-03-31 16:35 ID:TMGtAGig

Okay, I actually tested those this time, and for me, fac is about 1/3 slower and allocates 10% or so more memory than either fac' or fac'' on GHC 6.6 without any flags.

Name: Anonymous 2007-03-31 20:21 ID:G01N4nEk

xor ecx, ecx
_hoho:
add ecx, 1
cmp [ecx], 10000
jl _hoho

hohohohoho

Name: Anonymous 2007-04-01 0:10 ID:Ozs+yM4s

xor ax,ax
lul:
inc ax
cmp [ax],10000
jl lul

might be a bit faster

Name: Anonymous 2007-04-01 0:19 ID:Ozs+yM4s

dammit, why did i copy pasta from 6, it should have been
xor ax,ax
lul:
inc ax
cmp ax,10000d
jl lol

[ax] would try to read memory from 0 to 10000 , thus causing access violations each and every time(not that there woudnt be a legitimate use to do so, and i have seen situations where it was actually needed), but not in this case..

Name: Anonymous 2007-04-01 0:25 ID:Ozs+yM4s

now for a factorial in asm:

mov ecx,n ; n is the variable n!
cdq ; clear edx, sign
xor eax,eax
inc eax
lbl:
imul ecx
dec ecx
jnz lbl
; eax now contains factorial, wasnt it fast :D

Name: Anonymous 2007-04-01 0:45 ID:gExp/h/C

>>7-8
use add 1 instead of inc.

Name: Anonymous 2007-04-01 0:50 ID:Ozs+yM4s

>>10
for what reason? inc is faster than add

Name: Anonymous 2007-04-01 0:56 ID:gExp/h/C

>>11
i don't think so tim

Name: Anonymous 2007-04-01 1:27 ID:QiyrpEOD

>>1
Not on my system. Anyway, almost all the time is spent doing the actual multiplication -- the overhead of callCC vs foldr is negligible. Change the (*) to (+), and you might actually be able to see the difference in overhead.

The current program spends almost all of its time in libgmp...

Name: Anonymous 2007-04-01 2:36 ID:qpfSC7D5

>>12
According to the Intel 8086 Opcode reference, an add reg16, mem is 3 cycles, whilst an inc reg16 is 2.

Name: Anonymous 2007-04-01 2:37 ID:qBiogR71

STOP TALKING ABOUT ASM IN MY CALLCC THREAD

Name: Anonymous 2007-04-01 2:41 ID:qpfSC7D5

>>14 here
How embarassing, seems like I misread. An add reg, imm is 2 cycles, just like an inc. However, it is shorter to type inc, so you save a few bytes on disk.

Name: Anonymous 2007-04-01 2:57 ID:gExp/h/C

>>16
;)

Name: Anonymous 2007-04-01 4:29 ID:R1rjl+mt

i like people who know asm and haskell. bottom-up, top-down.

Name: Anonymous 2009-01-14 14:53

WTF

Name: ​​​​​​​​​​ 2010-09-07 19:10

Name: Anonymous 2011-01-31 21:33

<-- check em dubz

Name: Anonymous 2011-02-03 4:06

Name: Sgt.Kabu댯㼙kiman䌔푈 2012-05-28 23:50

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Name: Anonymous 2013-09-01 10:34


And so while I'm walking down the mall, a bunch of the girls are riding their bikes with the starchy dresses. And they all go down this one hall, and I follow them and it leads to some sort of arcade thing, but its like a private arcade, and so you have to wait in line like to get in like a club. I wait around awhile, but no one is let through so I walk off. I decide to head back to my apartment/dorm/hotel room. On the way back to the entrance of the mall I see a bunch of Japanese girls cosplaying Vocaloids and Touhou characters.

Name: Anonymous 2013-09-01 11:19


I just saw a truck driving down the train tracks. It looked much like this pic but white and had yellow flashing lights. I guess it is probably for maintenance.

Don't change these.
Name: Email:
Entire Thread Thread List