It is often stated that human languages, as other biological systems, areshaped by cost-cutting pressures but, to what extent? Attempts to quantify thedegree of optimality of languages by means of an optimality score have beenscarce and focused mostly on English. Here we recast the problem of theoptimality of the word order of a sentence as an optimization problem on aspatial network where the vertices are words, arcs indicate syntacticdependencies and the space is defined by the linear order of the words in thesentence. We introduce a new score to quantify the cognitive pressure to reducethe distance between linked words in a sentence. The analysis of sentences from93 languages representing 19 linguistic families reveals that half of languagesare optimized to a 70% or more. The score indicates that distances are notsignificantly reduced in a few languages and confirms two theoreticalpredictions, i.e. that longer sentences are more optimized and that distancesare more likely to be longer than expected by chance in short sentences. Wepresent a new hierarchical ranking of languages by their degree ofoptimization. The new score has implications for various fields of languageresearch (dependency linguistics, typology, historical linguistics, clinicallinguistics and cognitive science). Finally, the principles behind the designof the score have implications for network science.