3 ms·
web infrastructure is not the same as web development...infrastructure is what allows developers and users to build and use the apps. C does make sense for thes
by weatherlite 4y ago
web infrastructure is not the same as web development...infrastructure is what allows developers and users to build and use the apps. C does make sense for these things.
Stuff like Curl I think is written in C more due to historical reasons (Unix is written in C so all of its apps are in C), I don't see any major con if it was written in Python (which is a big high level wrapper over C in the end...) - it would be a tad slower and a bit more memory yeah, but in todays world I don't know how much of a difference it makes.
- _gabe_ 4y ago> I don't see any major con if it was written in Python > it would be a tad slower a tad? I'll use C++ as an example, but the last time I profiled a hash map in C++ vs C#, the C++ lookup took 1 nanosecond[0] and the C# version took 1ms (1000x slower) (I don't have these metrics anymore but I believe it was one ms or slower, and Google seems to confirm that). Now, if the difference between C++, a machine compiled language, and C#, a runtime compiled language, is 1000x for a very common operation, how much slower will an interpreted language that is running at an even higher level be?? The reason 90% of our apps are such slow trash these days is because programmers think that there is no difference in a couple milliseconds when it is a huge difference if that couple milliseconds is being run thousands of times through hundreds of thousands of lines of code! Take a look at how fast the Jai compiler is compared to a modern C++ compiler. Or even a C compiler vs a C++ compiler. It's night and day because of how much cruft slowly gets added on. So I find your claim that most of the Unix utilities are only written in C because that was mainstream in the day highly dubious. If anything, they would be written in something like Rust today, but definitely not JS or Python. Edit: I would also like to point out how much of a pain it would be to write low level network code, like what's necessary in curl, in a language like Python. When you're writing low level net code you want as little interference between the bytes and the programming language. Because if your bytes have some hidden padding, or the endianess is swapped, or a data structure is aligned a byte off, it means the difference between between correct transfer over the net, and sending garbage over the net. Python is not conducive at all to understanding how an object will be transformed into q series of bytes, whereas C is almost a direct translation from a struct to a series of bytes. [0]: https://gist.github.com/ambrosiogabe/66a6e2fdc77e6a600e570f4639222120 https://gist.github.com/ambrosiogabe/66a6e2fdc77e6a600e570f4...
- weatherlite 4y agoI might be wrong about curl - I use it just as a tool to make http calls but it might be more complicated than that - but why can't you build curl with python's http libraries? I guess there are use cases where you have to manipulate responses on the byte level?
- deleted 4y ago[deleted]
- nayuki 4y ago> the C++ lookup took 1 nanosecond[0] and the C# version took 1ms (1000x slower) The ratio between 1 ns and 1 ms is a million.
- flohofwoe 4y agoThe link talks about nano- vs micro-seconds, so probably just a typo.
- _gabe_ 4y agoI just re-ran the benchmarks and I was mis-remembering those statistics quite a bit. It looks like C# takes 124.5 nanoseconds on average for a hash set lookup. This was benchmarked using BenchmarkDotNet :)
- cpurdy 4y agoC# definitely does not take 1ms to look up something in a hash map. Perhaps 1us (microsecond) in a horrible example if the virtual hash code has a slow algorithm and doesn't cache the result. Regardless, the benefit of not using C++ is and always has been: Not having to use C++.
- _gabe_ 4y agoYep you are correct, I was mis-remembering quite a bit. I just re-ran the tests using BenchmarkDotNet and C# takes 124 nanoseconds on average, which is still 100x slower and a considerable difference, but not orders of magnitude difference :) C# benchmarks on my machine. FastFindRecipe just does a hash set lookup, it looks like this: private static readonly HashSet<CraftingRecipe> FastList = new HashSet<CraftingRecipe>(new CraftingComparer()); public static CraftingRecipe? FastFind(CraftingRecipe r) => FastList.TryGetValue(r, out var res) ? res : null; | Method | Mean | Error | StdDev | Min | Max | |--------------- |---------:|--------:|--------:|---------:|---------:| | FindRecipe | 315.2 ns | 1.17 ns | 1.09 ns | 313.6 ns | 317.4 ns | | FastFindRecipe | 124.5 ns | 0.23 ns | 0.21 ns | 124.1 ns | 124.9 ns |