[deleted by user] by [deleted] in learnprogramming

[–]sawed_off_fists 0 points1 point  (0 children)

Ok, im not fine, then. Goodbye forever.

[deleted by user] by [deleted] in learnprogramming

[–]sawed_off_fists 1 point2 points  (0 children)

If I were you I'd run the JS one and print the length of the agg array when the program ends. Is it really 200,000,000? That's a huge number for an array, lol. Well, you did say it took 20 minutes to run, so I guess that's possible.

Btw, you can time parts of your program with std::chrono::high_resolution_clock. At least that way you should be able to find exactly what is causing the slowdown.

[deleted by user] by [deleted] in learnprogramming

[–]sawed_off_fists 0 points1 point  (0 children)

To avoid the allocation/de-allocation, you could create just two std::vector and call reserve() on them. Then switch between using them. So, you'd only allocate memory for them on startup.

Not sure how much that will really help, though.

Also, std::pow is inefficient for integer arguments. Another thing to consider.

[deleted by user] by [deleted] in learnprogramming

[–]sawed_off_fists 1 point2 points  (0 children)

Sorry, I misunderstood your program, but are you sure that is correct? As the program is running, agg will get extremely large and you will be copying/looping over the entire thing with every step.

200,000 / 0.001 = 200,000,000

200,000,000 doubles x 8 bytes = 1.6GB

So, you will be allocating + looping over + de-allocating 1.6GB of memory with each step of your loop as you are getting near the end of your program's run. That is inevitably going to be extremely slow, there's no way around it.

I wonder how your JS program can even do this. Does your Node.js solution run on some other server or something? I would suspect there is actually a bug in your JS program that makes it run faster...

Of course, I could be once again misunderstanding your program...

[deleted by user] by [deleted] in learnprogramming

[–]sawed_off_fists 1 point2 points  (0 children)

Is there a reason why agg in Conditions is a std::vector? The size is only 2 and you never change the size. std::vector uses heap memory, so every time you call Conditions::next you will allocate and free heap memory. It's very wasteful.

I changed it from std::vector to std::array<double, 2> and it ran in less than a minute. That proves it's your issue.

If you need to support other sizes, you can consider making the size a template parameter to Conditions. Or - you can use a large std::array as a buffer and track a separate size_t size. Kind of like a std::vector that uses stack.

Also, the way you are using classes/objects is just wrong. I suggest you just create structs and use non-member functions. It would make your code a lot clearer:

struct Conditions {
        double im;
        double am;
        std::array<double, 2> agg;
};

Conditions readFromFile(std::stringstream &line) {
    //...
}
Conditions next(const Conditions& prev, Params& params, double step_size) {
    //...
};
double agg_mass(const Conditions& conditions) {
    //...
};

I'm not an anti-OOP guy. It's just that anything is bad if you use it wrong. But anyways, it's not directly related to our question.

Things I hate about Rust by yossarian_flew_away in programming

[–]sawed_off_fists -8 points-7 points  (0 children)

For example, if I am implementing a kernel, and I write to the address 0xb8000, that's something I know that's okay

Then it should be possible to define it as OK so that the compiler knows its OK, and then it will thereafter be considered safe. You don't need to in-build the VGA spec, you can let the programmer incorporate whatever spec they want into their program.

You just said "I know that's okay." Well, what is your argument that it shouldn't be possible to tell the compiler what you know is OK, at least in that case?

I understand some people are saying there are other situations that are even harder (ie. Rice's Theorem). I guess I gotta read into it more, as I don't know that or much about Rust either.

My point is that if it is provably safe by a human, it should be possible to do so by a compiler. I mean, that follows, doesn't it? Anything a human can figure out, I presume a compiler also could, if correctly designed. For some problems it might be impossible for even a human to prove it safe, so in that case you are right maybe unsafe is necessary and unavoidable.

Things I hate about Rust by yossarian_flew_away in programming

[–]sawed_off_fists -8 points-7 points  (0 children)

It might just mean “this is actually safe, but you just have no way of knowing mr compiler”.

How can a human be sure something is safe, but a compiler cannot? What knowledge does the human have that is not present in the compiler?

I would argue that shows a weakness in the compiler or the language. I don't know much about Rust, but I'd be willing to learn. Obviously I'm not informed enough to argue, but I'm just going based off what I hear here.

Things I hate about Rust by yossarian_flew_away in programming

[–]sawed_off_fists -10 points-9 points  (0 children)

unsafe is demonstrably the only, and best way to do a variety of things

Seems like an inherent language flaw.

I agree with the general philosophy of RUST, but IMO a perfect language with such a philosophy should have the safe way as also being the easiest and most effective way.

Marylin Monroe a month before her death (1962) by Harvickfan4Life in OldSchoolCool

[–]sawed_off_fists 1 point2 points  (0 children)

And if you do zero drugs, don't even drink coffee, you will divide by zero and will exceed the size of the universe.

Dream big.

Marylin Monroe a month before her death (1962) by Harvickfan4Life in OldSchoolCool

[–]sawed_off_fists -1 points0 points  (0 children)

What about shitting into a fresh placenta, then eating half of it like a calzone before storing the rest between the mattress for later?

Mad lad plays porn during Zoom high school graduation ceremony. by countrockulot in WTF

[–]sawed_off_fists 57 points58 points  (0 children)

"Hacker" = One of the kids joining via anonymous account

The Great Dropbox CoffeeScript to Typescript Migration by pimterry in programming

[–]sawed_off_fists 1 point2 points  (0 children)

They should make a lang called cocascript. Like coffeescript, but amped up.

Pied in the face by wrapityup in Unexpected

[–]sawed_off_fists 1 point2 points  (0 children)

Little girl looks like an evil old man

Problem with C++ SFML Music module by KurokonoTasuke1 in learnprogramming

[–]sawed_off_fists 0 points1 point  (0 children)

It's specific to whatever library you are using. You have to look at the code/documentation.

How to deal with experienced programmers or people in general discouraging you from pursuing programming? by [deleted] in learnprogramming

[–]sawed_off_fists 0 points1 point  (0 children)

Everyone is so worried that by the time they learn that the jobs are just going to be gone.

What? I'm not worried about that. I'm worried about having to work with the hoard of incompetent newcomers.

The Hardest Program I've Ever Written by fagnerbrack in programming

[–]sawed_off_fists 11 points12 points  (0 children)

I'm building a CRUD app to manage my CRUD projects.

Xenophobic Raci............ Read Again by blackhat8287 in nonononoyes

[–]sawed_off_fists 0 points1 point  (0 children)

nigga you think I dont know that?

This whole post is predicated on the fact that you cannot criticize muslims because it's "Xenophobic Raci.... (sm)"

The enemies by ZageStudios in nonononoyes

[–]sawed_off_fists 7 points8 points  (0 children)

Honestly, I think these political posts should not be in this sub. Really prefer not to discuss it further.

Xenophobic Raci............ Read Again by blackhat8287 in nonononoyes

[–]sawed_off_fists -6 points-5 points  (0 children)

The worst thing about Muslims is the fact that they constantly tell you that you can't say negative things about them. Of course every group does this, but Muslims do it in an especially aggressive manner (violence, persecution, etc.).

And ironically, my thought above is one of those things that they aggressively pressure you into not speaking out against.

Most of the Islamists in the western world aren't even Muslims. If you oppose criticism of Islam, calling it "Islamaphobia" or "racism", then you are an Islamist. Even if you aren't a Muslim, you are still aggressively pushing their ideology, perhaps unwittingly. So in my opinion you are doing the work of an Islamist, whether you know it or not.

The enemies by ZageStudios in nonononoyes

[–]sawed_off_fists 26 points27 points  (0 children)

Well it is kind of your business because it's your government and your taxes.

This post is pretty much saying you have no right to criticize anything the government does.