Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 04/13/23 in all areas

  1. No, not always - that's why it says "Measure, don't guess". Anyway apart from being Java, that article is over 10 years old and things change - libraries get optimized (yes, even Java ) I have no idea how the various pieces at play are implemented in Java - so why don't you simply run your own benchmark? I explicitly did not mention search but wrote insert or delete. I am well aware of the fact that access to contiguous memory is so much faster than random memory access that I know that if you add searching to the use case the more costly insert/delete can become totally irrelevant simply because the search is so much faster. Of course, usually, you don't just insert or delete to a linked list but also perform some search to determine the location where to insert or delete which is the reason why many benchmarks also include search. I know a lot of literature mentions using linked list + hashtable but I would probably simply use a queue or deque that is backed by a circular array buffer. If there is anything to take away from the article you linked to then it is this: This is because it completely ignores constant factors. Constant factors are why often the fastest algorithms and data structures, in reality, are hybrids that combine different algorithms. IntroSort is a good example that combines QuickSort with InsertionSort (for small sizes) and switches to HeapSort for QuickSorts worse cases. If you would ask "Which is better: QuickSort or InsertionSort?" Many people would say "QuickSort" but the the fact is that it depends on the number of elements. Similar to the question "Which is faster: a hashtable or linear search in an array?" Again it depends on several factors: the number of elements, the expense of comparison and hashing, and the actual implementation of the hashtable. And talking about the O(n) for inserting or deleting from a list. Here is a little benchmark and the results from Delphi 10.4 and 11.3: program BenchListInsertDelete; {$APPTYPE CONSOLE} uses Spring.Benchmark, System.Generics.Collections; procedure InsertDelete(const state: TState); var list: TList<Integer>; i: Integer; _: TState.TValue; begin list := TList<Integer>.Create; list.Capacity := 1000; for _ in state do begin for i := 1 to 1000 do list.Insert(0, i); for i := 1 to 1000 do list.Delete(0); end; end; begin Benchmark(InsertDelete, 'insert-delete').MinTime(2); Benchmark_Main(); Readln; end. Delphi 10.4.2 ---------------------------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------------------------- insert-delete/minTime:2,000 223341 ns 223644 ns 11947 Delphi 11.3 ---------------------------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------------------------- insert-delete/minTime:2,000 41379 ns 41487 ns 68923 You can guess why that is
  2. The AI search engine for developers. https://www.phind.com/
  3. Hi all, I'm pleased to announce the new release (v1.7.0) of the Sempare Template Engine. It has been a while, and thought I'd just remind any users here about the project. Also included are some demos... for apps in general, there is a new helper class TTemplateRegistry, which should make things much easier to just get going and supports template reloading without restarting the app and can load templates from file, resources, or custom a loader. This takes some of the grunt work out of working with templates, besides just using them. More information is available in the docs on the repo. Some simple examples are provided to illustrate server side scripting. If you have any suggestions, or see any gaps, please feel free to provide comments on the issue tracker. - Demo using the Horse framework - Demo using WebBroker standalone console app New features: - improved support for comments - extends/block template support - improved whitespace removal - renamed demo app to Sempare Template Engine Playground - a useful tool for testing language features / templates. - added the Sempare.Template.RCGenerator project to help with creating resource rc files by scanning directories. - support multiple statements in a script block. e.g. <% print('a'); print('b') %> - additional context configuration - improved docs (improved navigation and added railroad diagrams to illustrate the grammar) Older release notes can be viewed on the releases page. Have fun.
  4. programmerdelphi2k

    Radio button options not remembered on re-opening app

    @Willicious try some like this: type TForm1 = class(TForm) RadioGroup1: TRadioGroup; Button1: TButton; Memo1: TMemo; BtnLoadRadioButtons: TButton; BtnSaveRadioButtons: TButton; procedure BtnLoadRadioButtonsClick(Sender: TObject); procedure BtnSaveRadioButtonsClick(Sender: TObject); private procedure MySaveRadioGroup; procedure MyLoadRadioGroup; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} (* 0) Adapt your class to handle the desired components! 1) always try actions in "Try...Except" block! 2) in Form creating, your controls may not have been created yet!!! *) procedure TForm1.MySaveRadioGroup; var LMemStream: TMemoryStream; LControl : TControl; begin // TRY... EXCEPT ... END!!! LMemStream := TMemoryStream.Create; try for var i: integer := 0 to (RadioGroup1.ControlCount - 1) do begin LControl := RadioGroup1.Controls[i]; LMemStream.WriteComponent(LControl); end; // LMemStream.SaveToFile('MyRadioButtonsSavedOnDisk.bin'); finally LMemStream.Free; end; end; procedure TForm1.MyLoadRadioGroup; var LMemStream: TMemoryStream; LControl : TControl; begin // TRY... EXCEPT ... END!!! if FileExists('MyRadioButtonsSavedOnDisk.bin') then begin LMemStream := TMemoryStream.Create; try LMemStream.LoadFromFile('MyRadioButtonsSavedOnDisk.bin'); // for var i: integer := 0 to (RadioGroup1.ControlCount - 1) do begin LControl := RadioGroup1.Controls[i]; LMemStream.ReadComponent(LControl); // // TGroupButton = class(TRadioButton) on "implementation seccion" // TGroupButton is a "internal" type to TRadioButton usage!!! Memo1.Lines.Add(LControl.ClassName); end; finally LMemStream.Free; end; end else ShowMessage('File not found!'); end; procedure TForm1.BtnLoadRadioButtonsClick(Sender: TObject); begin MyLoadRadioGroup; end; procedure TForm1.BtnSaveRadioButtonsClick(Sender: TObject); begin MySaveRadioGroup; end; end.
  5. You should use a TRadiogroup instead of individual TRadiobuttons. You can then save and restore the ItemIndex of the group-
  6. Added a small demo. Does it work, show and demonstrate what you try to do? IniExample.zip
  7. As is obvious by my comments, I don't think this is all it's hyped up to be right now. That said, yesterday I used ChatGPT to give me a very quick overview of the "Mac way" of enumerating optical media drives on the computer. Rather than digging in to SO posts or looking through google results to find a general outline or (the horror), using Apple's insanely badly designed developer documentation website, I just asked ChatGPT to write an objective-c program that lists the optical drives on the computer. While I have no idea of the code it gave me would compile, it did show me the right API to use and one way of getting the results I want. I have no idea how much time this saved me. Maybe 30 minutes? Now I will just translate it's general idea into functional Delphi code. This is the second time I have used it for positive effect. So, it does have use. For me, it seems like a sometimes more efficient way of doing a web search to get an outline of how to solve a small programming problem.
×