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
>>59865263
i do but time added ~0.05 seconds
>>59865230
>>59865277
Thanks for taking the bait gentlemen :^)
>>59865135
Nobody cares about memory complexity anymore
>>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
>>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
>>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
>>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
>>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)))
>>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
>>59867716
op here, i'm not even mad
>>59868180
OP here, all real programmers respect that C++ is faster than Python
>>59868180
OP here, fuck you i'm learning C++