On Thursday, 23 December 2021 at 16:13:49 UTC, Stanislav Blinov
wrote:
You're comparing apples and oranges.
When benchmarking, at least look at
the generated assembly first.
I looked now and you're right. Insomuch that it should be
eggplant not apple, banana not orange...:)
Because it's an
On Thursday, 23 December 2021 at 07:14:35 UTC, Salih Dincer wrote:
It seems faster than algorithms in Phobos. We would love to see
this in our new Phobos.
Replace: 436 msecs
Malloc : 259 msecs
*/
It seems because MallocReplace is cheating a lot:
- it is not called through another function
On Thursday, 23 December 2021 at 07:14:35 UTC, Salih Dincer wrote:
It seems faster than algorithms in Phobos. We would love to see
this in our new Phobos.
```d
void mallocReplace()
void normalReplace()
string result = str.replace(';',"");
}/* Console Out:
Replace: 436 msecs
Malloc
On Monday, 13 December 2021 at 09:36:57 UTC, Ola Fosheim Grøstad
wrote:
```d
@safe:
string prematureoptimizations(string s, char stripchar)
@trusted {
import core.memory;
immutable uint flags =
GC.BlkAttr.NO_SCAN|GC.BlkAttr.APPENDABLE;
char* begin =
On Friday, 10 December 2021 at 18:47:53 UTC, Stanislav Blinov
wrote:
Threshold could be relative for short strings and absolute for
long ones. Makes little sense reallocating if you only waste a
couple bytes, but makes perfect sense if you've just removed
pages and pages of semicolons ;)
On Monday, 13 December 2021 at 05:46:06 UTC, forkit wrote:
On Saturday, 11 December 2021 at 09:25:37 UTC, Ola Fosheim
Grøstad wrote:
```putchar(…)``` is too slow!
On planet Mars maybe, but here on earth, my computer can do
about 4 billion ticks per second, and my entire program (using
On Saturday, 11 December 2021 at 09:25:37 UTC, Ola Fosheim
Grøstad wrote:
```putchar(…)``` is too slow!
On planet Mars maybe, but here on earth, my computer can do about
4 billion ticks per second, and my entire program (using putchar)
takes only 3084 ticks.
Of course, since it is easy to mess up and use ranges in the
wrong way, you might want to add ```assert```s. That is most
likely *helpful* to newbies that might want to use your kickass
library function:
```
auto helpfuldeatheater(char stripchar)(string str) {
struct voldemort {
On Sunday, 12 December 2021 at 08:58:29 UTC, Ola Fosheim Grøstad
wrote:
this(string s)@trusted{
begin = s.ptr;
end = s.ptr + s.length;
}
}
Bug, it fails if the string ends or starts with ';'.
Fix:
```
this(string s)@trusted{
On Saturday, 11 December 2021 at 19:50:55 UTC, russhy wrote:
you need to import a 8k lines of code module that itself
imports other modules, and then the code is hard to read
I agree.
```
@safe:
auto deatheater(char stripchar)(string str) {
struct voldemort {
immutable(char)*
On Saturday, 11 December 2021 at 18:51:12 UTC, Rumbu wrote:
On Saturday, 11 December 2021 at 14:42:53 UTC, russhy wrote:
Here is mine
- 0 allocations
- configurable
- let's you use it how you wish
- fast
You know that this is already in phobos?
```
"abc;def;ghi".splitter(';').joiner
On Saturday, 11 December 2021 at 14:42:53 UTC, russhy wrote:
Here is mine
- 0 allocations
- configurable
- let's you use it how you wish
- fast
You know that this is already in phobos?
```
"abc;def;ghi".splitter(';').joiner
```
Here is mine
- 0 allocations
- configurable
- let's you use it how you wish
- fast
```D
import std;
void main()
{
string a = "abc;def;ab";
writeln("a => ", a);
foreach(item; split(a, ';'))
writeln("\t", item);
string b = "abc;def ;ab";
writeln("a => ",
On Saturday, 11 December 2021 at 09:40:47 UTC, Stanislav Blinov
wrote:
On Saturday, 11 December 2021 at 09:34:17 UTC, Ola Fosheim
Grøstad wrote:
void donttrythisathome(string s, char stripchar) @trusted {
import core.stdc.stdlib;
char* begin = cast(char*)alloca(s.length);
A
On Saturday, 11 December 2021 at 09:34:17 UTC, Ola Fosheim
Grøstad wrote:
void donttrythisathome(string s, char stripchar) @trusted {
import core.stdc.stdlib;
char* begin = cast(char*)alloca(s.length);
A function with that name, and calling alloca to boot, cannot be
@trusted ;)
On Saturday, 11 December 2021 at 09:34:17 UTC, Ola Fosheim
Grøstad wrote:
@system
Shouldn't be there. Residual leftovers… (I don't want to confuse
newbies!)
On Saturday, 11 December 2021 at 08:46:32 UTC, forkit wrote:
On Saturday, 11 December 2021 at 08:05:01 UTC, Ola Fosheim
Grøstad wrote:
Using libraries can trigger hidden allocations.
ok. fine. no unnecessary, hidden allocations then.
// --
module test;
import
On Saturday, 11 December 2021 at 09:26:06 UTC, Stanislav Blinov
wrote:
What you're showing is... indeed, don't do this, but I fail to
see what that has to do with my suggestion, or the original
code.
You worry too much, just have fun with differing ways of
expressing the same thing.
On Friday, 10 December 2021 at 23:53:47 UTC, Ola Fosheim Grøstad
wrote:
```d
char[] dontdothis(string s, int i=0, int skip=0){
if (s.length == i) return new char[](i - skip);
if (s[i] == ';') return dontdothis(s, i+1, skip+1);
auto r = dontdothis(s, i+1, skip);
r[i-skip] =
On Saturday, 11 December 2021 at 08:46:32 UTC, forkit wrote:
On Saturday, 11 December 2021 at 08:05:01 UTC, Ola Fosheim
Grøstad wrote:
Using libraries can trigger hidden allocations.
ok. fine. no unnecessary, hidden allocations then.
// --
module test;
import
On Saturday, 11 December 2021 at 08:05:01 UTC, Ola Fosheim
Grøstad wrote:
Using libraries can trigger hidden allocations.
ok. fine. no unnecessary, hidden allocations then.
// --
module test;
import core.stdc.stdio : putchar;
nothrow @nogc void main()
{
string str =
On Friday, 10 December 2021 at 18:47:53 UTC, Stanislav Blinov
wrote:
Threshold could be relative for short strings and absolute for
long ones. Makes little sense reallocating if you only waste a
couple bytes, but makes perfect sense if you've just removed
pages and pages of semicolons ;)
On Saturday, 11 December 2021 at 00:39:15 UTC, forkit wrote:
On Friday, 10 December 2021 at 22:35:58 UTC, Arjan wrote:
"abc;def;ghi".tr(";", "", "d" );
I don't think we have enough ways of doing the same thing yet...
so here's one more..
"abc;def;ghi".substitute(";", "");
Using
On Friday, 10 December 2021 at 22:35:58 UTC, Arjan wrote:
"abc;def;ghi".tr(";", "", "d" );
I don't think we have enough ways of doing the same thing yet...
so here's one more..
"abc;def;ghi".substitute(";", "");
On Friday, 10 December 2021 at 18:47:53 UTC, Stanislav Blinov
wrote:
Oooh, finally someone suggested to preallocate storage for all
these reinventions of the wheel :D
```
import std.stdio;
char[] dontdothis(string s, int i=0, int skip=0){
if (s.length == i) return new char[](i - skip);
On Friday, 10 December 2021 at 06:24:27 UTC, Rumbu wrote:
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The character I want to skip: `;`
Expected result:
```
abcdefab
```
Since it seems there is a contest here:
```d
On Friday, 10 December 2021 at 12:15:18 UTC, Rumbu wrote:
I thought it's a beauty contest.
Well, if it's a beauty contest, then i got a beauty..
char[("abc;def;ab".length - count("abc;def;ab", ";"))] b =
"abc;def;ab".replace(";", "");
Yes it will. You can use lazy templates instead, like splitter and joiner,
which splits and joins lazily, respectively. LDC can optimize those templates
fairly well and avoid too much lazy calls and pretty much constructs the logic
equivalent to for loop.
On 10 December 2021 11:06:21 WET,
On Friday, 10 December 2021 at 18:47:53 UTC, Stanislav Blinov
wrote:
Be interesting to see if this thread does evolve into a SIMD
http://lemire.me/blog/2017/01/20/how-quickly-can-you-remove-spaces-from-a-string/
On Friday, 10 December 2021 at 13:22:58 UTC, Matheus wrote:
My C way of thinking while using D:
import std;
string stripsemicolons(string input){
char[] s = input.dup;
int j=0;
for(int i=0;i
Oooh, finally someone suggested to preallocate storage for all
these reinventions of
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
...
The character I want to skip: `;`
My C way of thinking while using D:
import std;
string stripsemicolons(string input){
char[] s = input.dup;
int j=0;
for(int i=0;i
On Friday, 10 December 2021 at 11:06:21 UTC, IGotD- wrote:
On Friday, 10 December 2021 at 06:24:27 UTC, Rumbu wrote:
Since it seems there is a contest here:
```d
"abc;def;ghi".split(';').join();
```
:)
Would that become two for loops or not?
I thought it's a beauty contest.
```d
string
On Friday, 10 December 2021 at 06:24:27 UTC, Rumbu wrote:
Since it seems there is a contest here:
```d
"abc;def;ghi".split(';').join();
```
:)
Would that become two for loops or not?
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The character I want to skip: `;`
Expected result:
```
abcdefab
```
Since it seems there is a contest here:
```d
"abc;def;ghi".split(';').join();
```
:)
On Thursday, 9 December 2021 at 18:00:42 UTC, kdevel wrote:
PRO:
- saves two lines of boilerplate code
CONS:
- raw loop
- postinc ++ is only permitted in ++C
- inconsistent spacing around "="
- mixing tabs and spaces for indentation
- arrow code
more PROs:
- You become less dependent on
On Wednesday, 8 December 2021 at 14:16:16 UTC, bauss wrote:
[...]
string b = a.replace(";", "");
On Wednesday, 8 December 2021 at 13:01:32 UTC, BoQsc wrote:
[...]
I'm not getting used to the syntax and that leads to poor
readability.
It depends on what you expect when you read source code. I don't
want to read how seats in the memory are assigned to bits and
bytes. Instead I want to
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The string example to loop/iterate:
```
import std.stdio;
void main()
{
string a="abc;def;ab";
}
```
The character I want to skip: `;`
Expected result:
```
abcdefab
On Wednesday, 8 December 2021 at 22:55:02 UTC, forkit wrote:
On Wednesday, 8 December 2021 at 22:35:35 UTC, Stanislav Blinov
wrote:
You're passing a literal. Try passing a runtime value (e.g. a
command line argument). Also, -O2 -release :) Uless, of
course, your goal is to look at debug
On Wednesday, 8 December 2021 at 22:35:35 UTC, Stanislav Blinov
wrote:
You're passing a literal. Try passing a runtime value (e.g. a
command line argument). Also, -O2 -release :) Uless, of course,
your goal is to look at debug code.
but this will change nothing.
the compilation cost of
On Wednesday, 8 December 2021 at 22:18:23 UTC, forkit wrote:
It's also worth noting the differences in compiler output, as
well as the time taken to compile, these two approaches:
(1)
string str = "abc;def;ab".filter!(c => c != ';').to!string;
(2)
string str = "abc;def;ab".replace(";", "");
On Wednesday, 8 December 2021 at 14:27:22 UTC, BoQsc wrote:
On Wednesday, 8 December 2021 at 14:16:16 UTC, bauss wrote:
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The string example to loop/iterate:
```
import
On Wednesday, 8 December 2021 at 14:16:16 UTC, bauss wrote:
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The string example to loop/iterate:
```
import std.stdio;
void main()
{
string a="abc;def;ab";
}
```
The
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The string example to loop/iterate:
```
import std.stdio;
void main()
{
string a="abc;def;ab";
}
```
The character I want to skip: `;`
Expected result:
```
abcdefab
On Wednesday, 8 December 2021 at 12:49:39 UTC, Adam D Ruppe wrote:
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
The string example to loop/iterate:
foreach(ch; a) {
}
does the individual chars of the string you can also
foreach(dchar ch; a) {
}
to decode the utf 8
Thanks
On Wednesday, 8 December 2021 at 11:35:39 UTC, Biotronic wrote:
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The string example to loop/iterate:
```
import std.stdio;
void main()
{
string a="abc;def;ab";
}
```
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
The string example to loop/iterate:
foreach(ch; a) {
}
does the individual chars of the string you can also
foreach(dchar ch; a) {
}
to decode the utf 8
On Wednesday, 8 December 2021 at 11:23:45 UTC, BoQsc wrote:
Let's say I want to skip characters and build a new string.
The string example to loop/iterate:
```
import std.stdio;
void main()
{
string a="abc;def;ab";
}
```
The character I want to skip: `;`
Expected result:
```
abcdefab
Let's say I want to skip characters and build a new string.
The string example to loop/iterate:
```
import std.stdio;
void main()
{
string a="abc;def;ab";
}
```
The character I want to skip: `;`
Expected result:
```
abcdefab
```
49 matches
Mail list logo