Re: Benchmark Dlang vs Node vs Ruby
On Friday, 27 May 2016 at 14:46:47 UTC, llaine wrote: On Friday, 27 May 2016 at 14:17:16 UTC, Adam D. Ruppe wrote: On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote: I am doing something wrong ? So, the benchmark, the Ruby, and the JS all use the path to be / the D seems to use /companies (though I don't know vibe). Is that right? All right after switching of psql client I had lower results actually ... Req/Sec 22.85 for 30 seconds. What are you using to do web if you don't user Vibe.d? Your code is not doing the same thing in the benchmarks. In D, you are appending 1 companies on every request, resulting in 1, 2, 3, companies in subsequent requests.
Re: Benchmark Dlang vs Node vs Ruby
On Friday, 27 May 2016 at 13:45:23 UTC, llaine wrote: Hi guys, In my journey of learning about D I tried to benchmark D with Vibe.d vs node with express and Ruby with Sinatra. And the results are pretty surprising. I have to admit that I though D was more faster than that. How is this even possible ? I am doing something wrong ? Here are the numbers with the project : https://github.com/llaine/benchmarks/blob/master/README.md The postgres library (dpq) that you're using doesn't use the event loop that vibe-d provides. Every call you are doing is blocking the whole server. Of course this is going to be slow. You can try using http://code.dlang.org/packages/vibe-d-postgresql.
Re: getting started with std.csv
On Tuesday, 7 April 2015 at 05:51:33 UTC, yazd wrote: On Tuesday, 7 April 2015 at 05:49:48 UTC, yazd wrote: I got this to work with: ``` import std.stdio, std.file, std.csv, std.range; void main() { std.file.write(test.csv, 0,1,abc\n2,3,def); scope(exit) std.file.remove(test.csv); static struct Rec { int a, b; char[] c; } auto file = File(test.csv, r); foreach (s; csvReader!Rec(file.byLine().joiner(\n))) { writeln(struct - , s); } } ``` I am not sure about using `file.byLine()` here, because `byLine` reuses its buffer, but this is working correctly (for some reason, anyone can comment?) as far as I tested. Btw, joiner is a lazy algorithm. In other words, it doesn't join the whole file when it is called but only when needed. This reduces the memory requirements as you won't need the whole file in memory at once. Replace `std.range` with `std.algorithm`.
Re: getting started with std.csv
On Tuesday, 7 April 2015 at 05:49:48 UTC, yazd wrote: I got this to work with: ``` import std.stdio, std.file, std.csv, std.range; void main() { std.file.write(test.csv, 0,1,abc\n2,3,def); scope(exit) std.file.remove(test.csv); static struct Rec { int a, b; char[] c; } auto file = File(test.csv, r); foreach (s; csvReader!Rec(file.byLine().joiner(\n))) { writeln(struct - , s); } } ``` I am not sure about using `file.byLine()` here, because `byLine` reuses its buffer, but this is working correctly (for some reason, anyone can comment?) as far as I tested. Btw, joiner is a lazy algorithm. In other words, it doesn't join the whole file when it is called but only when needed. This reduces the memory requirements as you won't need the whole file in memory at once.
Re: getting started with std.csv
I got this to work with: ``` import std.stdio, std.file, std.csv, std.range; void main() { std.file.write(test.csv, 0,1,abc\n2,3,def); scope(exit) std.file.remove(test.csv); static struct Rec { int a, b; char[] c; } auto file = File(test.csv, r); foreach (s; csvReader!Rec(file.byLine().joiner(\n))) { writeln(struct - , s); } } ``` I am not sure about using `file.byLine()` here, because `byLine` reuses its buffer, but this is working correctly (for some reason, anyone can comment?) as far as I tested.
Re: What does dmd 2.066 want from me?
If you have just installed a newer compiler and trying to link with older compiled code, then linking and other things can get wrong. I suggest recompiling all of your code using the new compiler.
Re: std.file.readText() extra Line Feed character
On Thursday, 18 December 2014 at 10:16:38 UTC, Colin wrote: On Thursday, 18 December 2014 at 09:25:47 UTC, ketmar via Digitalmars-d-learn wrote: On Thu, 18 Dec 2014 09:18:35 + Colin via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Why does std.file.readText() append a Line Feed char onto the end of the string? I have a file with the following contents in it: Name = Int Other=Float One More = String(Random;) I then have the code: void main(string[] args){ const text = Name = Int Other=Float One More = String(Random;); string input = readText(args[1]); writefln(Raw data); writefln(D)%s, cast(ubyte[])text[$-5..$]); writefln(File) %s, cast(ubyte[])input[$-5..$]); } This produces: Raw data D)[100, 111, 109, 59, 41] File) [111, 109, 59, 41, 10] Any Idea why the reading from the File adds on that extra '10' character? I don't think it's my editor adding chars to the end of the file, as I'm using vi. you *definetely* has the last line ended with '\n'. I dont see how, I copy and pasted from the string definition in D, directly after the first and directly before the last . If I look at the file in vim with line numbers turned on, the file is like this. So I really dont think I have a new line in the file... 1 Name = Int 2 Other=Float 3 One More = String(Random;) You can make sure using `hexdump -C file`. I tested locally creating a file using vi, and it does indeed have a '\n' at the end of file.
Re: HTML Parsing lib
On Saturday, 25 October 2014 at 19:44:25 UTC, Suliman wrote: I found only https://github.com/Bystroushaak/DHTMLParser But I can't get it work: C:\Users\Dima\Downloads\DHTMLParser-master\DHTMLParser-masterdmd find_links.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser11parseStringFAyaZC11dhtmlparser11HTM LElement find_links.obj(find_links) Error 42: Symbol Undefined _D11dhtmlparser12__ModuleInfoZ --- errorlevel 2 Is there any other HTML parsing lib, or maybe someone do know how to get it's work. Look like it's not compatible with current version of DMD You can try https://github.com/bakkdoor/gumbo-d
Re: std.container.Array deep-copy?
On Thursday, 9 October 2014 at 21:24:55 UTC, qznc wrote: On Thursday, 9 October 2014 at 21:14:46 UTC, qznc wrote: How can you deep-copy a std.container.Array instance? Ok, the deep-copy problem already got resolved on reddit: Use dup. However, the error is still open. You cannot give an Array!X argument to constructor/replace/insertBefore of Array!X instances? You will just need to slice it to provide a range.
Re: std.container.Array deep-copy?
Like the following? That did not work. Array!Foo y = Array!Foo(x[]); How does it not work? It compiles successfully: http://dpaste.dzfl.pl/583d20e426a0
Re: line numbers in linux stack traces?
On Sunday, 5 October 2014 at 17:12:28 UTC, Vladimir Panteleev wrote: On Sunday, 5 October 2014 at 09:10:06 UTC, Nick Sabalausky wrote: I know this keeps getting asked every year or so, but I couldn't find recent info. Are line numbers in linux stack traces supposed to be working at this point? Not the ones that the program itself prints on an unhandled exception. The main problem is with licensing (GPL). See here for details: https://d.puremagic.com/issues/show_bug.cgi?id=1001 Because I'm not getting any with 2.066.0 with either -g or -gc even when running under gdb. Kind of a pain, esp. compared to D dev on windows. It should work when running under gdb. Make sure you're using a recent gdb and you're not stripping the binary. If you link as a separate step, you may need to pass -g to DMD during linking as well. For delegates invoked through the runtime, or to see stack traces of crashes inside the runtime/phobos, you may need to rebuild Phobos and Druntime with -gs. Don't use -gc, it is no longer relevant. Btw, I have some code that parses elf/dwarf and maps addresses to file/line information here: https://github.com/yazd/elf-d It can be adapted for druntime and used to show better stack traces.
Re: Building library
On Thursday, 28 August 2014 at 19:29:40 UTC, papaboo wrote: Hey I've just started getting into D and so far I'm just messing around with it in a small math library. However I've run into an issue while trying to build a library and linking it with my main file. My current file and module layout is test.d src/math/vector.d - module dragonfly.math.vector src/math/quaternion.d - module dragonfly.math.quaternion Compiling with $ dmd test.d src/math/vector.d src/math/quaternion.d ./test works perfectly and runs the way I would expect. I then tried to compile a library as described http://ddili.org/ders/d.en/modules.html, so basically $ dmd src/math/vector.d src/math/quaternion.d -lib -ofmath -w $ dmd math.a test.d ./test But this fails with the following error test.d(5): Error: module vector is in file 'dragonfly/math/vector.d' which cannot be read I realize I placed my files in a 'src' dir instead of 'dragonfly', but shouldn't explicitly declaring the module name in vector.d and quaternion.d fix that? I'm compiling with dmd v 2.065 Hope someone has an answer for me so I can continue experimenting with D. When compiling test.d, the compiler needs to find the function signatures/struct declarations and so on that rely on the other modules. To do that, you have to include the other modules for the compiler to read. You can do that by: dmd test.d math.a -Isrc ./test When you are using -I flag, the included files are NOT compiled, but can be thought of as being used as headers in C/C++. One other note, note that you should include 'src' folder, and the files would be found properly using the module - filesystem mapping.
Re: Reading ELF Files
On Friday, 2 May 2014 at 15:25:55 UTC, Nordlöw wrote: On Friday, 2 May 2014 at 10:42:40 UTC, yazd wrote: On Thursday, 1 May 2014 at 17:31:52 UTC, Nordlöw wrote: Here you go, https://github.com/yazd/elf-d. Thanks! Anytime. By the way, if you need more stuff out of it or help, post an issue on github. I think I'll be able to help a bit more. But if this library is to move forward, the API will need a redesign. You might want to keep that in mind. Ok. Great! Some reflections: - This is not a robust way of detecting limitations of the package (elf.d): static assert(is(size_t == ulong), only 64bit is supported for now); This static assert needs to be called at run-time on the header contents of the mmapped file itself. - It is nice that you use MMFile. I do that too in my engine. However, to make cooperation more flexible and efficient class ELF should provide a ctor that takes and existing MMfile as argument (refernce) during construction, since my file engine class RegFile temporarily creates such instances when neeeded. BTW: What does package keyword mean in the line package MmFile file; inside the definition of ELF. For detail see for example: https://github.com/nordlow/justd/blob/master/fs.d#L1192 You're correct in terms of the check. Anyway, I have just pushed some changes to support both 32bit and 64bit elf binary files. That required minor changes in the API, but it should still be easy. And I've added a constructor that takes an MmFile. `package` here is a protection attribute. From the documentation on dlang.org, Package extends private so that package members can be accessed from code in other modules that are in the same package. This applies to the innermost package only, if a module is in nested packages.
Re: Reading ELF Files
On Thursday, 1 May 2014 at 17:31:52 UTC, Nordlöw wrote: Here you go, https://github.com/yazd/elf-d. Thanks! Anytime. By the way, if you need more stuff out of it or help, post an issue on github. I think I'll be able to help a bit more. But if this library is to move forward, the API will need a redesign. You might want to keep that in mind.
Re: Reading ELF Files
On Thursday, 1 May 2014 at 11:38:50 UTC, Nordlöw wrote: Have anybody put together some D code for reading out tables from ELF files? A range/slice based version would be nice. I have some simple proof of concept code. It is currently able to read elf64 (can be easily adjusted to read elf32 too) headers, extract sections and read string tables. If this is what you need, then I'll upload my code somewhere (although again, it is quite simplistic). If you specify what you need a bit more, I might be able to provide that.
Re: Reading ELF Files
On Thursday, 1 May 2014 at 13:10:33 UTC, Nordlöw wrote: again, it is quite simplistic). If you specify what you need a bit more, I might be able to provide that. Please, post :) Here you go, https://github.com/yazd/elf-d.
Re: Writing to stdin of a process
On Saturday, 26 April 2014 at 08:45:59 UTC, Craig Dillabaugh wrote: I want to be able to write to the stdin stream of an external process using std.process. I have the following small test app. myecho.d -- import std.stdio; void main(string[] args) { foreach (line; stdin.byLine()) { stdout.writeln(line); } } -- If I call this from the command line, it echo's back whatever I write to it. Then I have the following program. testpipes.d --- import std.process; import std.stdio; void main( string[] args ) { auto pipes = pipeProcess(./myecho, Redirect.stdin ); scope(exit) wait(pipes.pid); pipes.stdin().writeln(Hello world); } If I compile and run testpipes.d, nothing happens. I was expecting it to echo back Hello world to me. Can anyone tell me what I am dong wrong. What you are missing is a call to flush() after writeln(). This is necessary for pipes as they are only automatically flushed if an internal buffer is full, AFAIK.