How to get current time in milliseconds in Rascal - rascal

I want to debug a slow function in Rascal, to find out why it is slow. To do this, I want to save the system time in milliseconds at certain locations so I can measure the time taken by certain parts of the code.
I have looked at the DateTime module (http://tutor.rascal-mpl.org/Rascal/Expressions/Values/DateTime/DateTime.html), but it does not seem easy to compute time differences this way.
Is there any better way?

There is a buildin profiler in rascal, that does function and statement level profiling. You can enable it with :set profiling true in the repl.
If you want to do benchmarking, take a look at util:;Benchmark

Related

Is there any way I can get a performance summary Results(Scripting, Rendering, Idle time)?

I want to capture chrome performance summary. Scripting, Rendering, Loading, Idle and Other time programatically. I want know is there any metrics lighhouse generates which I can use?.
I have tried https://github.com/axemclion/browser-perf. It doesn't calculate Other and idle time. I looked at chromium source code (TimeLineUtil.js) to see if I can use the same logic to capture these details. It seems bit complex. Thought of asking this question here. If anyone already implemented the same.
You are probably looking for The Page Speed API: https://developers.google.com/speed/docs/insights/v5/reference/pagespeedapi/runpagespeed#response. Or is that insufficient?

How to implement the mach_absolute_time Swift api?

This may be a bit of a silly question, but I'm looking for a reliable way to create a repeating timer in Swift that's as completely accurate as possible. I've researched this quite a bit and have found that the mach_absolute_time api seems to be what I'm looking for.
However, while I think I understand mach_absolute_time, there's not much out there on mach_wait_until (if I understand correctly that's the mach api version of using Timer.scheduledTimer() to call a selector).
So my goal is to turn something like Martin R's answer to this post: Measuring Time Accurately in Swift for Comparison Across Devices into a timer that can measure out an exact amount of time, call a selector, and repeat with little to no loss of time between ticks.
Thanks!
Update
The other thing I ran into is that the timer can't lock up the app while the it's running either – I know since mach is pretty low level, calling mach_wait_until will stop everything else and wait for the time to elapse (I think).

Does the time reported in z3 (v4.4.0) statistics include the time required to read the SMT constraint file?

Or is it purely the solving time? This question is for the case when z3 is being called as an external binary. I am asking this as in some of my examples, the constraint solving time is small and I suspect will become comparable to file read time. Also, how accurate is the total-time for small values (< 1s for example)?
Yes, the total time should include the time need to read the problem. Those numbers are 'reasonably' precise, but not totally exact. In our own performance experiments, we usually use higher precision external timers, but usually we don't need to measure the load time.
If you're getting into the region where the load time and the solving time are both very small, then it would be best to switch to the API instead of dumping .smt2 files and then calling an external binary.

Analyzing code path in Objective C a la TraceGL?

TraceGL is a pretty neat project that allows JS programmers to trace code paths in Javascript. It looks something like this:
I'd like to build something similar for Objective C. I know the runtime has made it rather easy to trace method calls, but how would I trace control flow? For example, in the screenshot above, code paths not executed are made obvious with a red highlight. What would be the best way to achieve something similar in an Objective C/Xcode workflow?
The best I've come up with so far is to write a preprocessor that injects code into temporary source files before sending them to the compiler. Anyone have a better idea?
I guess the visualizer for issues found by Xcode's static analyzer comes pretty close to this - albeit this one will only give you the call path for a particular issue like a memory leak.
Try "Product > Analyze" in Xcode, select any of the issues found on any given project and click on the blue arrow in the code editor to see for yourself.
Not exactly answer for Objective C and XCode.
For C++ code there is a industrial quality code coverage tool BullseyeCoverage
Function coverage gives you a quick overview and condition/decision coverage gives you high precision
Works with everything you can write in C++ and C, including system-level and kernel mode
If you want to invent/write this kind of tool yourself I'd recommend to take a look at (evaluate) some existing tools that solve the same task so that you don't miss a key functionality
There are basically 2 categories of such tools
working at binary level, instrument byte code, library entry points etc.
working at source level, instrument source code before going to the compiler
The purpose of the instrumentation is to insert into the code calls to a profiling runtime that collects the runtime statistics for further processing.
Basic calls
timestamp, thread id, source code address, entering
timestamp, thread id, source code address, leaving
The source code address depends on the granularity you are interesetd in. It can be a function name ot it can be a source file and line number.
Collected performance data can be quite huge so they are usually summed-up and whole callstacks are not captured. It is usually sufficient level of detail for detecting performance bottlenecks.
Another drawback is that capturing detailed performance data especially in code points with many hits will slow the application significantly.
If you want complete history then capture the full trace including timestamps and thread-ids and you will be able to recreate the call stacks later knowing that each enter has corresponding leave.
To guarantee this pairing the code instrumentation must insert exception handling calls to make sure that exit point will be logged even if the function throws an exception (what is the "exception" and how to try-finally it dependes on the language and the OS platform).
To get all necessary tricks and tips evaluate some tools and take a look at their instrumentation style.
BTW: in general it is quite a lot of work to do and to get right I'd personally thought twice or more times about what will be the outcome and what will be the costs.
As a want-to-play-with topic I fully recommend that. I created such a tool for troubleshooting Java MIDP applications working at C++ source level and Java binary level and it was helpful at the time when we needed it.

Guessing the time zone from an arbitrary "location" string?

I'm trying to run some statistics over the Stack Overflow data dump, and for that I would like to know the time zone for each user. However, all I have to go on is the completely free-form "location" string.
I'll stress that I'm only looking for an approximation of the time zone; of course, in general this is an unsolvable problem. However, many people fill out their country, state and/or city, which should give a pretty good indication. It's okay if it fails for other cases. It doesn't have to be reliable, it doesn't have to be accurate, it doesn't have to cover all bases.
I don't want to waste too much time on this, so I'm wondering if there is some code out there that can make a reasonable guess. Any language, platform, API or library goes. Any ideas?
Check this discussion for information on how to get the lat/lon from an arbitrary location string.
Once you have the lat/lon, you can use the web services at GeoNames to retrieve the time zone.

Resources