last day (15 days later) » 

10:10 AM
21
Q: I created something much faster than a std::string

xeerxI've recreated std::string in a way that might be faster. System Features: Much faster than std::string. Easy to use. It was designed as part of a large database so it is very fast and good at handling memory. Responsive to all types of data, you can enter characters, numbers, even decimal nu...

 
Ehm, I appreciate the enthusiasm, but are you sure that is comparable with a fully fledged std::string implementation? As a useful exercise I hope you continue and improve your code (I would check for genericity, interoperability, rule of five, const correctness, exception safety, how to include c headers, avoidable macros, pre-increments as default, no identifiers prefixed with underscores, coherent formatting, no endl and using namespace, ...)
 
@MatG Thank you very much for these suggestions, I will be glad if you tell me more, I may have been quick to judge the project, so I hope the experts can give me more advice
The code is being improved, please wait one more day and try it again, thank you
 
If you’re looking to improve this code, the absolute number one thing you should do is test it properly. You have written “tests” that only compare the speed of your class against std::string… but nowhere did you bother to test whether your class actually works. Spoiler: it doesn’t; all you’ve managed to prove with those tests is that your class is dead wrong around twice as fast as std::string is correct (and only with optimizations off!). Not great, hm? Correctness first; optimization later. Make it workthen make it fast. You can’t skip that first step.
 
@indi i will do it, thank you
 
Besides the issue of correctness, Quick C++ Benchmark is a good tool for comparing run-time performance.
 
10:10 AM
You've wasted a lot of time trying to get std::string fast in unoptimized debug builds... Benchmark code the way it'll be used in production: using release builds, which normally have most optimizations turned on, except very expensive ones.
 
One other bit of advice: your copyright notice is not in the legally-correct form (at least in the United States). I would recommend that you use a standard license vetted by the Open Source Initiative.
 
+1 not just for the attempt, but for the second final note: this is a fantastic mindset to have!
 
There is no “legally-correct” form of copyright notice, not in the US nor anywhere else in the world that I’m aware of. That’s a long-running myth based on ancient law. Copyright notices are always optional. What’s there is… fine, I guess. 🤷🏼 But since it doesn’t allow anything, it doesn’t really serve a purpose; saying nothing would have had the same effect. Standard licences are fine if you want to allow some usage, with specific limits… but if you’re just saying “hard no” they don’t help any.
 
Commercial use of this file is prohibited without written permission is a bit redundant. You already said All rights reserved, which means nobody else can redistribute your code at all, or build anything that needs to include it. As @Davislor and indi said, your copyright notice didn't grant any permission to anyone for anything. If you intended it to be open-source, that's not how to do it.
my mistake does not mean my end, on the contrary, I will learn from this mistake - glad you were able to take the right lesson from this. Writing code that isn't as good as you hoped doesn't make you a bad person (especially if it was a learning exercise), it just means you have more to learn. We all do. The optimism of your idea that this is faster than std::string is amusing, but I'm sure next time you'll remember that microbenchmarking is hard, and sometimes standard libraries are slow, but often not.
 
@indi To be a bit pedantic, a particular form of copyright notice is required by the Copyright Act of 1976 to defeat an innocent-infringement defense in court and be able to collect any damages, not to hold a copyright at all.
 
10:10 AM
What a great question - not just for the question itself, and the character shown in the edits, but for the truly great answers it has provoked.
 
@PeterCordes You say that "nobody else can redistribute your code at all", but that's not true. Anyone who possess a lawfully-made copy can give it to someone else. Since it was uploaded to a site that provides anyone who wishes with a lawfully-made copy, in practice, distribution of the unmodified code is not really significantly restricted. See 17 USC 109(a).
 
@DavidSchwartz: Interesting. I guess that's a consequence of uploading it to StackExchange, which I hadn't considered. But it's still true that nobody could distribute this code along with their own code that #include<>ed this header, without something like the LGPL; that would otherwise count as a derivative work. They could just distribute their own code and leave it to the user to find their own copy of xstring, but that's highly inconvenient. LAME (LAME is not An Mp3 Encoder) was originally something like that, a set of patches to non-free but source-available code, I think.
 
At the time string was introduced it had a performance bottleneck. I replaced it with my own version, keeping in the string a small buffer of say 32 chars. Then short strings would not need to allocate a char* besides the string object itself, which often just lived on the stack.
 
I totally agree with everyone else: this is a fine start, and you have the right attitude! Great question.
 

last day (15 days later) »