Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 07/21/21 in all areas

  1. Short answer is: Ordinary human response in workplace (not gaming) tends to be around 150-200mS. So in dealing with button click responses, the processing overhead in this situation is irrelevant.
  2. Version3 is the best because its maintainable and gives compile error if anyone decides to add a new value - while cases don't and at best depending on the Compiler Version might give a warning about a non handled case. Also the benchmark is pointless because like 90% of the workload you test is string assignments - here is a screenshot from samplingprofiler: If you care for speed then get rid of the unnecessary function call. Unfortunately also depending on compiler version the inlining is not an option and rather makes things worse for functions returning managed types such as string You might be better by just directly indexing into the const string array.
  3. You're welcome. It took a lot of time to write. Good luck on your project. I'm headed back to coding. See the earlier post by @Stefan Glienke about your #3 being less likely to fail in the future if you change the enum definition.
  4. Mike, You asked me what I meant by digging "too deeply." Suppose you want to drive from New York City to San Francisco. It's about a 43-hour drive. Suppose your friend says, "Oh, I can make your trip shorter. When you get to Chicago, there's a very long stoplight you'll probably have to sit at for two minutes waiting for it to turn green. But, to avoid the slowdown, I know a great detour. It'll save you about a minute. Turn left when you get to Main Street, and then turn right at the next street, go two blocks, and then turn right again and then turn at the next left. This will take you around the block, avoiding the stoplight delay, and then rejoin your original route to continue on your way to San Francisco." Would you take the detour? The detour is faster than staying on the route with the long stoplight. But is it enough faster for you to worry about? Is it enough faster to bother taking? Is it enough faster to risk getting lost on the streets of Chicago? Is it enough faster to spend hours discussing on forums? How much faster should the detour be before you're willing to take it? How much risk can the detour add before you think to yourself, "I'm not going to take that detour." ??? In your code, you have no idea how long the trip is. You have no idea where the bottleneck slowdowns are. So, you have no idea if the proposed speedup will be significant. And people here in the forum are telling you that your detour (new code) may be riskier (i.e. more difficult to maintain.) Suppose your enum code is currently consuming a total of .0050 seconds every time a user clicks a certain button. Suppose you spend hours writing several versions of alternate code. Suppose your new code speeds up enum strings so that they're now TWICE AS FAST, so that processing enums only takes .0025 seconds. Was it worth your time to work on this? What many of us have been saying to you here and elsewhere is that the revisions (detours) that you're suggesting to speed up your code are insignificant and may bring risk. You need to learn how to put your efforts where they will have the biggest impact on improving your code. The first rule is WRITE THE CLEANEST, MOST MAINTAINABLE CODE YOU CAN. Then MEASURE your application with a performance monitor/profiler to identify places where it's slow. A profiler will help you do this by showing you exactly where your code is spending its time. It's likely that the amount of time your current code is spending on enum strings is infinitesimal compared to everything else your code is doing. So even if you speed up the enum code, the speedup is likely to have no impact on your users.
  5. Hi, Mike, No, this wasn't posted in the wrong thread. You said you were refactoring. There are two reasons to refactor code that I'm aware of: 1. Make it easier to maintain. 2. Significantly improve the speed of the software. To answer your question about which approach is better, we need to know of the above two are you doing? Since you've provided speed benchmarks, I assume that it's #2 -- you're trying to significantly speed up your software. I suspect that you are prematurely optimizing your code for speed before you know where the bottlenecks are. Have you used a profiler to determine where to best focus on speeding up your application? Even if you made this code infinitely fast, would you or your users be able to notice the difference? If your answer is "yes" – then we'd love to hear about this novel application. If your answer is "no" – then you're wasting your time.
  6. Result := GetEnumName (TypeInfo (TEnum), Ord (FEnum))); Angus
  7. No surprise that speed is the same... #1 and #2 are virtually the same, and they have one bitwise operation+one if+jump. #3 is just read from address. I always prefer #3 because compiler will control if number of elements change. Sometimes, if needed, I use combined #3&#2 approach (array[TEnum] = (cS1, cS2...)).
  8. That's correct. The question is what problem are you trying to solve? What is your purpose? I use a record helper to implement a two way conversion, string to enum, enum to string. The string forms are used in persisting values to a database. If you need custom strings, then you will incur a maintenance issue, one way or another. As I mentioned earlier, if different languages are a factor, then you may need a multi-dimensional array of string constants.
  9. Speed isn't the issue. The mistake that you make again and again. Maintainability is the only concern here.
  10. pyscripter

    New Community Edition

    In case you have not seen it: Delphi & C++Builder Community Editions Now Available in Version 10.4.2! (embarcadero.com)
  11. Lajos Juhász

    TJSONObject.Format bug

    A quick find in files returned that TJSon is implemented in the REST.Json.pas and it is not in your uses.
  12. Angus Robertson

    THttpAppSrv - Add*Handler for PUT and DELETE

    I'll look at adding the missing handlers in the next week or so. You may want to look at a new SSL sample, OverbyteIcsDDWebService.dpr which is very similar to OverbyteIcsSslMultiWebServ.dpr, but designed as a Windows service, although it will also run as a GUI for debugging. It requires DDService service framework to be installed from https://www.magsys.co.uk/delphi/ddservice. asp. It also includes a REST server with simple lookup responses from a SQL database, which optionally requires DISQLite3 to be installed from http://www.yunqa.de. Note this sample in not in the project groups due to these pre-requisites. This sample is part of the next release, in SVN and the overnight zip. It is effectively a working REST server, very similar to a commercial server I've written at https://api.telecom-tariffs.co.uk/ but you need a login to do actual REST requests. Angus
  13. I have nSoftware Red Carpet subscription and has used their AMQP component. Pros: - Very well documented APIs, and very good technical support. Cons: - Expensive - No source code
  14. Well, any typed const could be modified by pointer seems you recall ancient times when this was true indeed
  15. @mvanrijnen @Edwin Yip Thanks for the references. The aim with the Sempare Template Engine was to have a template engine that was native to Delphi and could be used for web, but also for other kinds of purposes such as code or config generation. At the time I wrote it, dmustache was mainly what was available, but I wanted a template language that was more readable and pascal-like, and from a library perspective providing more flexibility in terms of extension points (custom functions) and the ability to support various sub-template inclusion patterns (content with header/footer, main template referencing content template, etc) and dynamic loading. Due to the fact that looping is a feature, it also has to be safe and offers a timeout if template processing takes too long due to data processing or bad logic. It does rely on RTTI, which does mean there is a performance penalty, but I chose functionality/flexibility over performance to start. I have not had problems reported yet, so I suspect performance has been acceptable for users, as it has been for my use cases. Documentation wise, it should be fairly well covered on github, but I have been working on a CHM help edition which can be used from the IDE with context sensitive help which may be a bit more friendly for those that don't want to necessarily have to browse to the the github docs. Please email me conrad@sempare.ltd/conrad.vermeulen@gmail.com if you are interested and can notify you when it is available. If you have feature requests/comments feel free to raise them on the issue tracker (https://github.com/sempare/sempare-delphi-template-engine/issues). I do check here periodically, but may miss things or reply late. In the next release, I'm allowing for discovery of variables and functions that are referenced. So if you provide a template editor and are using a dictionary/json to pass variables, the UI can know upfront what the required variables are and perform additional validation if required, prompting the user if anything is missing. Alternatively, it could be a way to identify variables that are required, allowing for optimal querying of data from database before populating the template. This is just a complementary feature to an existing feature where errors can be raised if a referenced variable is not present. Further, I hope to create some more examples with more popular web frameworks soon, as I think many people find it easier to see how things work from demos. I realise licensing as GPL may be contentious, but I've gone with the 'free as in speech vs free as in beer' approach. So for a nominal one time fee, you can use it under the commercial license without any restriction. I'll keep you posted on new developments as they unfold.
  16. Fr0sT.Brutal

    JSON parsing question

    Hmm, I can't realize what puzzles you. Anyway you start from TJSONObject . Then grab its values one by one and check whether they're TJSONObject , TJSONArray or something else (using "is" operator).
×