Jump to content
Battlefront is now Slitherine ×

Big announcement... Battlefront is now Slitherine


Recommended Posts

On 10/12/2024 at 2:59 PM, Redwolf said:

Python is extremely slow, though. Unless you only use it as glue to connect C code modules (like they do in many machine learning frameworks).

And interfacing C# and Python will be no fun at all since you have to go through a C layer.

I have just now replaced a brute force Fortran implementation of a node-to-attached-elements search by a plain Python implementation using lists and dictionaries, and achieved a speed-up by a factor of one hundred!

The only problem now is how to explain to the customers why the function (not originally written by me, remark) was so slow in the first place.

Furthermore, I recommend everybody into programming to check out test driven development. It improves the quality of software right from the start. You just think differently about your code when you write the tests before the code itself. Learned pretty late about it, but am loving it already!

 

Link to comment
Share on other sites

2 hours ago, Thomm said:

I have just now replaced a brute force Fortran implementation of a node-to-attached-elements search by a plain Python implementation using lists and dictionaries, and achieved a speed-up by a factor of one hundred!

Totally OT but choosing the correct algorithm is where the real performance improvements are found. I am not familiar with modern Fortran implementations (last time I programmed in Fortran was 1992) but I doubt it is among the most performant language choices you can make.

Now if you are already using a python library that is implemented in C/C++ to do some of the heavy lifting then you could already be close to as fast as you can get. However if you hand wrote the implementation then you may well see another significant performance improvement if you were to switch to C/C++. See this article: https://www.freecodecamp.org/news/python-vs-c-plus-plus-time-complexity-analysis/

2 hours ago, Thomm said:

Furthermore, I recommend everybody into programming to check out test driven development. It improves the quality of software right from the start.

This is mostly a good thing, agreed.

2 hours ago, Thomm said:

The only problem now is how to explain to the customers why the function (not originally written by me, remark) was so slow in the first place.

Yeah, that can be an interesting discussion. Your tests from the test driven development approach will help with part of it. One objection will be "but is is really doing the same thing as the previous version". With a series of tests you can probably support your position that you *are* doing the same thing with the new code.

As for the objection "but why didn't you do this the first time". That one is challenging. You have to some how imply that previous developers did not do their job well without saying that outright 🙂 One approach could be that at first that code's performance didn't matter as much as now and that's why your company put the resources towards fixing it.

Link to comment
Share on other sites

1 hour ago, A Canadian Cat said:

However if you hand wrote the implementation then you may well see another significant performance improvement if you were to switch to C/C++. See this article: https://www.freecodecamp.org/news/python-vs-c-plus-plus-time-complexity-analysis/

Wow! I knew that C++ had a reputation for being fast. But I never wrote a program complex enough to appreciate the difference. So I had no idea how much faster it was compared to other languages (such as Python).

Link to comment
Share on other sites

35 minutes ago, Centurian52 said:

Wow! I knew that C++ had a reputation for being fast. But I never wrote a program complex enough to appreciate the difference. So I had no idea how much faster it was compared to other languages (such as Python).


Not only is the same code about 80 times slower on the same CPU, default Python threads also fail to make use of multiple CPUs/cores, which is a big issue on today's computers. As all CM players know.

Link to comment
Share on other sites

To be honest, the examples in the article look like something that you would import the NumPy module for instead of using plain Python loops. I would be more interested in a comparison of the higher level stuff like dynamic lists and dictionaries. In my application, a dictionary of dynamic lists, which takes a few seconds to set up in Python, but then provides access a hundred times faster than the original brute-force Fortran solution.

Link to comment
Share on other sites

5 hours ago, Thomm said:

To be honest, the examples in the article look like something that you would import the NumPy module for instead of using plain Python loops. I would be more interested in a comparison of the higher level stuff like dynamic lists and dictionaries. In my application, a dictionary of dynamic lists, which takes a few seconds to set up in Python, but then provides access a hundred times faster than the original brute-force Fortran solution.


Using the wrong data structures and algorithms will usually destroy performance much more than a slow language, at least if you have a reasonably large dataset.

Link to comment
Share on other sites

On 10/20/2024 at 12:25 AM, Albert DuBalay said:

In the event we don’t get the first battle of France, could we get the LAST battle of France 😁 ? French troops assault landing on Oleron Island end April 1945.

 

The lack of French forces in CM2 (just a couple of scenarios in CMFI that I'm aware of) has definitely left a noticeable gap in its representation of all eras. It would be great to see MAS-36s, FM-24/29s, 25mm Hotchkiss anti-tank guns, and R35s in action in 1940, MAS-49s and AMX-30s in action in a Cold War setting (still mostly hoping to see the Cold War Bundeswehr in action, but French forces in that era are too unique not to want as well), and FAMASs and Leclercs in action in a modern setting.

With the CM2 era coming to a close I'm hoping that CM3 will be able to give us a wider representation of forces and eras than CM2 ever could, including giving us more French forces. Supposedly a lot of the old bottlenecks on productivity have been widened or outright eliminated, so perhaps there's hope.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...