Explain this

protip: you can't

Other urls found in this thread:

youtube.com/watch?v=02a723LsoFA
ref.x86asm.net/geek.html#x40
twitter.com/SFWRedditGifs

Quality thread

...

You can't program for shit I guess because on my system a program that does this in C took 0.002 sec, and one in Haskell took 0.005. C was a simple for loop with an if statement, Haskell was mapM (putStr . (\x -> show x ++ " ")) $ filter odd [1 .. 99].
C used 3380 byes, Haskell used 3268. For C I used GCC, for Haskell GHC.

are you an hacker? is youre name anonymoose?

kys

Way to fuck with branch prediction, fam.

You're right because you didn't post the code you mongoloid.

dayum; well at least I also used a filtered [1 .. 99] instead of [1, 3 .. 99] in my haskell one

...

I'm not implying any of that and you know it, dunce.

BASIC can do that with less RAM so long as you're using an older machine.
10 FOR x = 1 TO 99 STEP 220 PRINT x30 NEXT x
That comes to ~16 bytes on an old 8 bit computer running tokenized BASIC.

lol i dont programme and i spend all my time shitposting on windows while pretending to use gentoo lol install gentoo xDDDD

There's nothing to explain. The minimum page size on any CPU architecture all three of those can run on is 4 kilobytes, so this image is lying.

10 PRINT "OP IS A FAGGOT"20 GOTO 10

Now do it in Assembly

ok kiddo

okay, smart ass, do it in Windows 10

ok kiddo

lmao kys

The average Holla Forums poster, everyone.

...

int i; for ( i = 1; i < 100; i += 2 ) printf ( "%d", i);

WeW lad.

int main(){ write(1,"1\n3\n5\n7\n9\n11\n13\n15\n17\n19\n21\n23\n25\n27\n29\n31\n33\n35\n37\n39\n41\n43\n45\n47\n49\n51\n53\n55\n57\n59\n61\n63\n65\n67\n69\n71\n73\n75\n77\n79\n81\n83\n85\n87\n89\n91\n93\n95\n97\n99\n",145);}

...

...

wew

Holy shit, kill yourself.

no real programming experience apart from the basic concepts, but i'd be interested in hearing the reason for not doing that

`int i` can be a char to save 1 byte, `%d` uses more memory than `%i` for some reason, and i` += 2` is more memory than `i++`used in the for and the printf

You should start at 1 and just iterate 2 at a time to save the odd check and cut your loop iterations in half.

These depend on your compiler, and on x86 processors, chars use up a whole register anyway, so there's not much point in using a char there.

listen to this IT professional explain it youtube.com/watch?v=02a723LsoFA

Didn't know Holla Forums was a character.

How about i++++?

Man this is embarrassing

...

That would be a super slow way of doing it because system calls are expensive I've read.
Better to use a loop and printf.

How do you think printf writes it?

printf is a c stdio function, not a system call. It uses buffering and so is fast. Or so I've read.

and then what does printf do with the buffered data?

Why would I care about how memory is being used as long as it gets the job done?
:'^)

is codeeval registration broken?

Here ya go, x86-64 Linux:
SECTION .textBITS 64GLOBAL _start_start: sub rsp, 150 mov rdx, rsp mov eax, 0x2031L1: mov [rdx], ax add rdx, 2 add eax, 2 cmp al, '9' jle L1 mov eax, 0x203131L2: mov [rdx], eax add rdx, 3 add eax, 0x0200 mov ebx, eax sub ebx, 0x09ff cmp eax, 0x203b00 cmovnc eax, ebx cmp al, '9' jle L2 mov BYTE [rdx-1], 0x0a mov eax, 1 mov edi, eax mov rsi, rsp sub rdx, rsi syscall mov eax, 60 xor edi, edi syscall
Compile with:
nasm -f elf64 count.Sld -s count.o -o count
because autism

very nice indeed

You just HAD to use it as an excuse to shill your BBC fetish!?!?

its a meme you stupid poltard dip

You still felt the urge to do it. It's okay, we won't judge you though.

bait thread #2018393422

speak for yourself

...

Underrated post.


Holla Forums never shuts up about Black Penises, I think it's them who has the fetish if you ask me.

Honestly, I'm a hardcore Holla Forumsack and this thread is the first time I see this shit. Are you sure you're not projecting?

im not expert does that only use registers and zero ram memory?

It allocates 150 bytes on the stack to hold the entire generated output and writes all of it to stdout in one kernel call right before exiting.

SECTION .data
fag db `\u004F\u0050\u0020\u0049\u0053\u0020\u0041\u0020\u0046\u0041\u0047\u0047\u004F\u0054`, 0

SECTION .text
global main

main:

mov edx, 14
mov ecx, fag
mov ebx, 1
mov eax, 4

...

kill yourself

What's wrong with Unicode Strings?

You forgot some codes:
int 80h
mov eax,1 ; exit()
mov ebx,0 ; return val
int 80h

yes i forgot

Nothing wrong with unicode strings, plenty wrong with utf-16 strings.

bampu

...

...

There is a grand total of one syscall here.

This kidn of shit is why i'm glad C is a thing.

Somewhere, a phpfag just said the same thing upon seeing a program written in C.

Please take this shit thread to 4/g/ where it belongs.

no

why?

This should have been checked long ago...

why?

Disregard doublepost, I suck cocks.

let's see how glorious LuaJIT handles this:
for i=1, 99, 2 do io.write(i)end

Results:
Command being timed: "./luajit ../../odd.lua"User time (seconds): 0.00System time (seconds): 0.00Percent of CPU this job got: 71%Elapsed (wall clock) time (h:mm:ss or m:ss): 0m 0.00sAverage shared text size (kbytes): 0Average unshared data size (kbytes): 0Average stack size (kbytes): 0Average total size (kbytes): 0Maximum resident set size (kbytes): 2320Average resident set size (kbytes): 0Major (requiring I/O) page faults: 0Minor (reclaiming a frame) page faults: 179Voluntary context switches: 1Involuntary context switches: 3Swaps: 0File system inputs: 0File system outputs: 8Socket messages sent: 0Socket messages received: 0Signals delivered: 0Page size (bytes): 4096Exit status: 0

and it still can be optimized as
local write = io.writefor i = 1, 99, 2 do write(i)end

OK, I had to try this with if and without if. Here is the "bad" code:
#include int main(int argc, char *argv[]) { for (int i = 0; i < 100; ++i) { if (i % 2) { printf("%d\n", i); }; }; return 0;}
Compiling with clang and -O3 yields
$ time ./badreal 0m0.005suser 0m0.001ssys 0m0.002s


Now let's try the "good" code:
#include int main(int argc, char *argv[]) { for (int i = 1; i < 100; i += 2) { printf("%d\n", i); }; return 0;}
Again compiling with clang and -O3
$ time ./goodreal 0m0.005suser 0m0.001ssys 0m0.003s

WTF is going on here? Using GCC instead of clang gives me the same results for both as the "good" code with clang.

gcc -S

i += 2 means i = i+2, there is an extra access to the i variable, while ++i changes the value directly

you should be using bitwise and with 1 instead of the modulo

This thread is painful to read. A new low for Holla Forums.

Unless there is an instruction that does single increments to variables that I'm not aware of, i++ is the same as i = i+1 which should compile in the same format as i = i+2

That's because the entire program, regardless of how you write it, executes extremely quickly and is drowned by the overhead of calling the kernel to actually output the output. Heck, this program spends much more time within printf than in its own code. Shit like that can only matter in hot sections of a larger computation that is not I/O bound.
It's still good not to let yourself fall into habit of writing shitty code, so that's that.
This, and an optimising compiler can plausibly unroll the "bad" version and transform it into the "good" version on its own - though don't count on it.


Not sure whether retarded or trolling.


Any compiler worth its salt will do that optimisation for you, and the intent of % is more obvious. Always favor code readability over micro-optimisation, unless the performance benefits of the latter are quantifiably worth it (and there are none at all here).


There is, not that it matters.

The optimal solutions don't have to be used as long as equivalent solutions are used, it's about the comparison.

I once had an actual pajeet iterate by 2s while some white TA started arguing with him saying that using modulo 2 to check for evens is a better solution.

Was not proud of my race tbh.

...

This beautiful thread obviously needs a bump.

This is like the "condition fabric" meme on /k/.

FP has literally no real world relevance

hopefully Hoon/Nock and Urbit change this soon.

Triggering faggots like you is relevant enough.

How is smug the same as triggered?

/g/'s looking pretty good today

it's my favrotie board XD

I don't get this, are we comparing the cost of printing, or the cost of calculation by someone who thinks

ref.x86asm.net/geek.html#x40

...

Who cares, as long as the thread is bumped.

I find it hard to believe anyone here would be smug about anything, let alone something so petty. I find it easier to believe that people masquerading as smug are just desperately after some interaction with others, that's very typical around here. Who actually knows and who cares either.

You tell me. Haskell isn't shit at it.

Neither, this thread is founded on completely wrong bullshit. See where it should have died.