[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Hey guys what do you think of my highly optimized code :^)?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 55
Thread images: 4

File: code.jpg (42KB, 371x273px) Image search: [Google]
code.jpg
42KB, 371x273px
Hey guys what do you think of my highly optimized code :^)?
>>
>Not using assembly
Come back when you're an actual programmer, kid.
>>
I actually kind of like cin/cout, it's a guaranteed indicator that the poster is a first semester CS student and doesn't know shit.
>>
>>59169662
What's better, passing in as an argument? Never really touched C++.
>>
>>59169662
>College
>Implying
>>
>>59169705
I'm fully convinced cin/cout was added to C++ to make it easier to do hello world.
>>
>>59169589

> optimized

Streams are very inefficient senpai.
>>
>>59169735
As opposed to what? printf? Give me a break.
>>
Well, at least you're using CodeBlocks.
>>
>>59169589
>no indentation
D R O P P E D
>>
>>59169786
That's what makes it optimized desu
>>
>>59169589
>no indentation
Unreadable.
>using a Windows IDE and probably a Windows compiler
>doesn't follow GNU standards
I barfed
>>
>>59169825
the compiler doesn't see whitespace
>>
>>59169827
What's a GNU standard?
>>
File: 1488126240517.jpg (32KB, 853x465px) Image search: [Google]
1488126240517.jpg
32KB, 853x465px
>>59169825
Indentations and comments are stripped by the compiler...
>>
rate
function isntprime(argument) {
while (true) if (argument % Math.floor(Math.random()*100) === 0) break
return true
}
>>
>>59169847
Example of the GNU standard:
int
main (int argc, char *argv[])
{
struct gizmo foo;

fetch_gizmo (&foo, argv[1]);

check:
if (foo.type == MOOMIN)
puts ("It's a moomin.");
else if (foo.bar < GIZMO_SNUFKIN_THRESHOLD / 2
|| (strcmp (foo.class_name, "snufkin") == 0)
&& foo.bar < GIZMO_SNUFKIN_THRESHOLD)
puts ("It's a snufkin.");
else
{
char *barney; /* Pointer to the first character after
the last slash in the file name. */
int wilma; /* Approximate size of the universe. */
int fred; /* Max value of the `bar' field. */

do
{
frobnicate (&foo, GIZMO_SNUFKIN_THRESHOLD,
&barney, &wilma, &fred);
twiddle (&foo, barney, wilma + fred);
}
while (foo.bar >= GIZMO_SNUFKIN_THRESHOLD);

store_size (wilma);

goto check;
}

return 0;
}
>>
return isPrime(input);


isPrime() is left as an exercise for the reader.
>>
>>59169840
>>59169872
But it makes the source code smaller
>>
>>59169988
who cares?
if you wanna compress text just tar and gzip it
>>
>>59169988

Yes, we all get this. Stop being a smartass.
>>
>>59169589
You need to be 18 years old to post here.
>>
>>59169662
>>59169735
This is the worst kind of person
>>
>>59169735
Tiers of C++ programmers:

>Newbie tier: thinks << syntax is so cool
>Disillusioned tier: le operator overloading is bad meme, le c++ is overcomplicated meme
>Ascended tier: found his inner peace, embraces the iostream
>>
>>59169662
>t. someone who has never written C++ for a living
>>
>>59169827
Kill yourself, you dumb fucking shit stain.
>>
Cs101
>>
>>59169589
Step it up.
|_  {bowl $~}
::
++ prim
|= x/@
=+ i=2
|- ^- ?
?: =(x i) &
?: =(0 (mod x i)) |
$(i +(i))
::
++ poke-noun
|= a/@
~& ?:((prim a) [a %is-prime] [a %not-prime])
[~ +>.$]
--
>>
>>59170131
Have you been following me around recently?
>>
>>59169662
WTF are you supposed to do for "solve this puzzle" type command line shit???
>>
>>59169589
I'm gonna hurt you
>>
for i:=1 to trunc(sqrt(x)) you retarded faggot
>>
>>59169589
>abusing namespace std;
>>
>>59170320
printf
>>
non-descriptive, cryptic code != Optimized code

I took the bait
>>
OP you only have to try factors up the square root of x
>>
>>59169589
>using the smiley with a carat nose
>>
step up your game nigga and use scanf/printf
>>
>>59171368
just fwrite to stdout
>>
>>59169589
No sieve of eratosthenes. Kill yourself.
>>
>>59171368
Why?
>>
>not putting it all on a single line
3/10, see me after class
>>
>>59171450

iostream is way slower than cstdio.
but, the compiler replaces your brain when you're using iostream, because it's using type safety.
>>
>>59169589
You should only loop until sqrt(x), all the other divisors can be obtained from x/i, where i is an integer smaller than sqrt(x).
For example:
Let's obtain the divisors of 20
1 2 4 5 10 20

Sqrt(20) is somewhere between 4 and 5.

20 is 20/1
10 is 20/2
And 5 is 20/4

So it's useless to check numbers above sqrt(x). Try it out!
>>
File: 1488157846436.png (549KB, 1023x574px) Image search: [Google]
1488157846436.png
549KB, 1023x574px
>>59169589
>"Enter a Positive Integer"
>1
>>
>>59169589
>highly optimized
>not using inline functions
>O(n) prime checker
>iostream and not write()
>unportable system() bullshit because you're too stupid to run your shit properly
>implying more chars = more slow
unreadable dogshit, 2/10
>>
>>59171902
>isPrime(1)
>skips the for loop because 2 > 1
>returns true
It works you stupid shit
>>
>>59169589
What does no formatting have to do with optimization?
>>
>>59169589
0/8 total piece of crap
>>
>>59169988
>optimizing for disk space
WHAT YEAR IS IT?
>>
>>59172121
1 is not prime
>>
File: a04.jpg (217KB, 1423x927px) Image search: [Google]
a04.jpg
217KB, 1423x927px
>>59172207
shut up, we are glad it finally works
>>
>i<x
>"""highly""" optimized
Agh
>>
>>59170298
Wew hoon
>>
>>59171616

You can also first check 2, then start the loop at 3 and increment by two each time - if the number is divisible by any even number, it is divisible by 2 anyway.
Thread posts: 55
Thread images: 4


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.