Skip to main content

Utilities and Debugging

Printing to console#

# Use print to write a string or an expression to output consoleprint('Hello World')
fruits = ['mango', 'apple']print(fruits)
print(5 * 15 + 20)
# Use printF to write a formatted stringprintF('%s World', 'Hello') # prints, Hello World

Know the time taken by a piece of code (benchmarking)#

# To know the time taken by following string replacement, use instant and elapsed functionsstart = instant()
text = 'Save your $$$. Now get $50 discount on every $500 spent.'pattern = '\\$(?<price>[1-9][0-9]{0,4})'replacement = 'USD${price}'replaceAll(text, pattern, replacement)
tookMicros = elapsed(start, timeUnit.microsecond)tookMillis = elapsed(start)printF('Total microseconds took by string replacement: %s', tookMicros)printF('Total milliseconds took by string replacement: %s', tookMillis)

Get a uuid (universally unique identifier)#

print(uuid()) # prints a uuid