[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]

So this is the power of python 2.7

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: 33
Thread images: 11

File: SumOfPrimesLessThan200Million.png (155KB, 1343x848px) Image search: [Google]
SumOfPrimesLessThan200Million.png
155KB, 1343x848px
The best part about this image is the ass blasted comments from game stop employees who took Intro to Java and larp they are programmers online.

Btw do you guys have battle toads?
>>
>>59865085

i dont get it.

you traded the memory complexity for time complexity?
>>
>>59865135
This is /g/. Stop expecting these "programmers" to know what memory complexity is. In fact I wouldn't be surprised if he didn't even know what time complexity was :^).
>>
>>59865206
>using the smiley with a carat nose
>>
>>59865085
>he doesn't know about the time command in *nix
>>
>>59865206

>knows what big O is
>thinks he's special
>>
Nice crypto desktop thread
>>
File: britney_spears_0152.jpg (200KB, 1600x1000px) Image search: [Google]
britney_spears_0152.jpg
200KB, 1600x1000px
>>59865263

i do but time added ~0.05 seconds
>>
>>59865230
>>59865277

Thanks for taking the bait gentlemen :^)
>>
>>59865135
Nobody cares about memory complexity anymore
>>
File: C6qclTTXAAAow31.jpg:large.jpg (12KB, 640x117px) Image search: [Google]
C6qclTTXAAAow31.jpg:large.jpg
12KB, 640x117px
>>59865206
>takes a discrete math class at community college
>now self declared king of /g/
>>
>>59865353
>retard spotted
People don't care about constant factors on memory usage anymore, but they damn sure care about memory complexity.
>>
>>59865353
People like you are cancer
>>
File: 1459910710548.png (58KB, 436x425px) Image search: [Google]
1459910710548.png
58KB, 436x425px
>>59865085
please rewrite it in C and glue it with Python
>>
The Sieve of Eratosthenes is pop-maths you should know from high-school, so don't think you can lord over those gamestop employees just yet.

If you're a beginner, then well done. Now learn Lisp.
>>
>>59865368
And honestly, even that's not true. Constant factors are still important, just not fixed costs.
>>
>>59865307
>using the smiley with a carat nose
>>
File: ivanka.jpg (94KB, 736x1102px) Image search: [Google]
ivanka.jpg
94KB, 736x1102px
>>59865085

Theme music for this thread. Thanks OP you are the hero python 2.7 deserves!

https://www.youtube.com/watch?v=ALZHF5UqnU4&list=RDQMOv95jIhGdkg
>>
File: Screenshot_2017-04-12_21-41-39.png (29KB, 562x338px) Image search: [Google]
Screenshot_2017-04-12_21-41-39.png
29KB, 562x338px
>>59865085
I don't get what this thread is about. But my sieve is faster, and uses less memory.
$ time python3 sieve_of_Eratosthenes2.py 
1075207199997334

real 0m33.612s
user 0m33.572s
sys 0m0.040s
>>
>>59867716
>python stronk!
Get in the slow lane. A real programming language is driving in the fast lane.

0.842868
1075207199997334
Program ended with exit code: 0
>>
>>59867716
>>59868180

#include <stdio.h>
void main() {
printf("1075207199997334\n");
}
>>
>>59868227
>implying
Test the code yourself faggot. Here it is in text form so you can copy/paste. If you even have or know how to operate a C compiler that is.

My time is from a Core i7 MBP using Xcode with optimizations on.

>33s vs. 0.8s
Yeah. Python is that fucking slow.

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#define ISBITSET(x, i) (( x[i>>3] & (1<<(i&7)) ) != 0)
#define SETBIT(x, i) x[i>>3] |= (1<<(i&7));
#define CLEARBIT(x, i) x[i>>3] &= (1<<(i&7)) ^ 0xFF;
typedef unsigned long long int lli;

lli sumPrimes(lli n)
{
lli m = (n-1) / 2;
lli bsize = m/8+1;
char* b = (char*)malloc(bsize * sizeof(char));
lli i = 0;
lli p = 3;
lli s = 2;
lli j;

memset(b, 255, bsize);
while (p*p < n) {
if (ISBITSET(b,i)) {
s += p;
j = (p*p - 3) / 2;
while (j < m) {
CLEARBIT(b, j);
j += p;
}
}
i += 1; p += 2;
}

while (i < m) {
if (ISBITSET(b,i)) {
s += p;
}
i += 1; p += 2;
}

return s;
}

int main(void)
{
static double time_consumed = 0;
clock_t start, end;
start = clock();

long long ans = sumPrimes(200000000);

end = clock();
time_consumed += (double)(end - start);
printf("%f\n", time_consumed / CLOCKS_PER_SEC);

printf("%lld\n", ans);
return 0;
}
>>
>>59868266
>My time is from a Core i7 MBP using Xcode with optimizations on.
what optimizations?
O1 :
0.675089
O2 :
0.6183089
O3 :
0.647160

use register keyword with loop variables
Don't use O3 as you code can't be vectorized in any way and contain no recursive call

>#include <math.h>
useless

>char* b = (char*)malloc(bsize * sizeof(char));
>memset(b, 255, bsize);
Timesink, you should put it outside sumprime if you want an accurate time.
also
>what is calloc

>no free
why? You used memset but not free.

You shouldn't use bit-manipulation macros with int if you want to manipulate long long int. It works here but not every times.
>>
>>59868615
>>My time is from a Core i7 MBP using Xcode with optimizations on.
>what optimizations?
Ofast.

>Don't use O3 as you code can't be vectorized in any way and contain no recursive call
Doesn't actually make a difference. Run multiple times at each setting, the variance from run-to-run for a setting is larger than the difference you pasted, and O3 or Ofast is just as likely to be faster on any given run as not.

>>char* b = (char*)malloc(bsize * sizeof(char));
>>memset(b, 255, bsize);
>Timesink, you should put it outside sumprime if you want an accurate time.
It's required to solve the problem so it's part of the time.

>also
>>what is calloc
malloc+memset forces the kernel to allocate the memory. calloc (depending on OS) might only allocate the address space. Page faults during processing would hammer processing time.

>>no free
>why? You used memset but not free.
You are right!

>You shouldn't use bit-manipulation macros with int if you want to manipulate long long int. It works here but not every times.
Another good point.
>>
I must really suck at c
> time ./a.out
Result: 1075207199997334
7.40user 0.08system 0:07.49elapsed 99%CPU


Actually just started reading K&R yesterday
>>
File: 1447188556678.jpg (62KB, 590x536px) Image search: [Google]
1447188556678.jpg
62KB, 590x536px
>>59865085
No, we don't have it in store but I can order it for you.
>>
>>59865085
Console font?
>>
>>59867716
Not bad, but just use the builtin sum at the end there.

print(sum(sieve(2e8)))
>>
File: ThomasBMcGuire.jpg (62KB, 350x411px) Image search: [Google]
ThomasBMcGuire.jpg
62KB, 350x411px
>>59865085

Congrats if you posted in this thread ABOVE this image you are one of the dozens of actual programmers on /g/. If you didn't and you are, better luck next time!
>>
>>59865307
>pretending
Sure thing
>>
File: imnotevenmad.jpg (305KB, 1280x720px) Image search: [Google]
imnotevenmad.jpg
305KB, 1280x720px
>>59867716

op here, i'm not even mad
>>
>>59868180

OP here, all real programmers respect that C++ is faster than Python
>>
File: obama.jpg (192KB, 1200x800px) Image search: [Google]
obama.jpg
192KB, 1200x800px
>>59868180

OP here, fuck you i'm learning C++
Thread posts: 33
Thread images: 11


[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.