I use the tuples command (from SSC). The tuples command is implemented in terms of python script and, optionally, uses Mata code.

I run the following script:

Code:
cls 
about
python query 

clear all
macro drop _all

numlist "1/17"

timer clear

// timing python script
timer on 1
tuples `r(numlist)'
timer off 1

macro drop _tuple*

// timing mata code
timer on 2
tuples `r(numlist)' , nopython
timer off 2

timer list

Here are results from Stata 16

Code:
Stata/IC 16.1 for Windows (64-bit x86-64)
Revision 14 Jun 2022
Copyright 1985-2019 StataCorp LLC

Total physical memory:       16.00 GB
Available physical memory:   10.67 GB

Stata license: Single-user  perpetual
Serial number: omitted
  Licensed to: omitted

. python query 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    omitted

    Python system information
      initialized          yes
      version              3.10.0
      architecture         64-bit
      library path         omitted\Python\Python310\python310.dll

omited

. timer list
   1:      2.47 /        1 =       2.4660
   2:      5.35 /        1 =       5.3530

Python does the job in about 2.5 seconds; in half the time it takes Mata.


Here are the results from the identical script in Stata 17:

Code:
. about

Stata/BE 17.0 for Windows (64-bit x86-64)
Revision 23 Aug 2022
Copyright 1985-2021 StataCorp LLC

Total physical memory:       16.00 GB
Available physical memory:   10.65 GB

Stata license: Single-user  perpetual
Serial number: omitted
  Licensed to: omitted

. python query 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    omitted
    
    Python system information
      initialized          yes
      version              3.10.4
      architecture         64-bit
      library path         omitted\Python\Python310\python310.dll

omitted

. timer list
   1:      6.54 /        1 =       6.5350
   2:      4.90 /        1 =       4.8980

Good news: Mata is faster now. Bad news: Python is much slower.

What is going on?