Skip to content

Instantly share code, notes, and snippets.

@evan2m
Last active July 17, 2019 19:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save evan2m/2706238 to your computer and use it in GitHub Desktop.
Save evan2m/2706238 to your computer and use it in GitHub Desktop.
Benchmark counters in python
import timeit
from shakespeare import LETTERS, WORDS
if __name__ == '__main__':
# defaultdict
t = timeit.Timer(stmt="""
counter = defaultdict(int)
for k in LETTERS:
counter[k] += 1
""",
setup="from collections import defaultdict; from shakespeare import LETTERS")
print "defaultdict letters: {0}".format(t.timeit(1000))
t = timeit.Timer(stmt="""
counter = defaultdict(int)
for k in WORDS:
counter[k] += 1
""",
setup="from collections import defaultdict; from shakespeare import WORDS")
print "defaultdict words: {0}".format(t.timeit(1000))
# setdefault
t = timeit.Timer(stmt="""
counter = dict()
for k in LETTERS:
counter.setdefault(k, 0)
counter[k] += 1
""",
setup="from shakespeare import LETTERS")
print "setdefault letters: {0}".format(t.timeit(1000))
t = timeit.Timer(stmt="""
counter = dict()
for k in WORDS:
counter.setdefault(k, 0)
counter[k] += 1
""",
setup="from shakespeare import WORDS")
print "setdefault words: {0}".format(t.timeit(1000))
# Counter
t = timeit.Timer(stmt="c = Counter(LETTERS)",
setup="from collections import Counter; from shakespeare import LETTERS")
print "Counter letters: {0}".format(t.timeit(1000))
t = timeit.Timer(stmt="c = Counter(WORDS)",
setup="from collections import Counter; from shakespeare import WORDS")
print "Counter words: {0}".format(t.timeit(1000))
print "{0} letters and {1} words".format(len(list(LETTERS)),len(list(WORDS)))
# This is the data we will use to benchmark
PLAY = """
ACT V. Scene I.
Mantua. A street.
Enter Romeo.
Rom. If I may trust the flattering truth of sleep
My dreams presage some joyful news at hand.
My bosom's lord sits lightly in his throne,
And all this day an unaccustom'd spirit
Lifts me above the ground with cheerful thoughts.
I dreamt my lady came and found me dead
(Strange dream that gives a dead man leave to think!)
And breath'd such life with kisses in my lips
That I reviv'd and was an emperor.
Ah me! how sweet is love itself possess'd,
When but love's shadows are so rich in joy!
Enter Romeo's Man Balthasar, booted.
News from Verona! How now, Balthasar?
Dost thou not bring me letters from the friar?
How doth my lady? Is my father well?
How fares my Juliet? That I ask again,
For nothing can be ill if she be well.
Man. Then she is well, and nothing can be ill.
Her body sleeps in Capel's monument,
And her immortal part with angels lives.
I saw her laid low in her kindred's vault
And presently took post to tell it you.
O, pardon me for bringing these ill news,
Since you did leave it for my office, sir.
Rom. Is it e'en so? Then I defy you, stars!
Thou knowest my lodging. Get me ink and paper
And hire posthorses. I will hence to-night.
Man. I do beseech you, sir, have patience.
Your looks are pale and wild and do import
Some misadventure.
Rom. Tush, thou art deceiv'd.
Leave me and do the thing I bid thee do.
Hast thou no letters to me from the friar?
Man. No, my good lord.
Rom. No matter. Get thee gone
And hire those horses. I'll be with thee straight.
Exit [Balthasar].
Well, Juliet, I will lie with thee to-night.
Let's see for means. O mischief, thou art swift
To enter in the thoughts of desperate men!
I do remember an apothecary,
And hereabouts 'a dwells, which late I noted
In tatt'red weeds, with overwhelming brows,
Culling of simples. Meagre were his looks,
Sharp misery had worn him to the bones;
And in his needy shop a tortoise hung,
An alligator stuff'd, and other skins
Of ill-shaped fishes; and about his shelves
A beggarly account of empty boxes,
Green earthen pots, bladders, and musty seeds,
Remnants of packthread, and old cakes of roses
Were thinly scattered, to make up a show.
Noting this penury, to myself I said,
'An if a man did need a poison now
Whose sale is present death in Mantua,
Here lives a caitiff wretch would sell it him.'
O, this same thought did but forerun my need,
And this same needy man must sell it me.
As I remember, this should be the house.
Being holiday, the beggar's shop is shut. What, ho! apothecary!
Enter Apothecary.
Apoth. Who calls so loud?
Rom. Come hither, man. I see that thou art poor.
Hold, there is forty ducats. Let me have
A dram of poison, such soon-speeding gear
As will disperse itself through all the veins
That the life-weary taker mall fall dead,
And that the trunk may be discharg'd of breath
As violently as hasty powder fir'd
Doth hurry from the fatal cannon's womb.
Apoth. Such mortal drugs I have; but Mantua's law
Is death to any he that utters them.
Rom. Art thou so bare and full of wretchedness
And fearest to die? Famine is in thy cheeks,
Need and oppression starveth in thine eyes,
Contempt and beggary hangs upon thy back:
The world is not thy friend, nor the world's law;
The world affords no law to make thee rich;
Then be not poor, but break it and take this.
Apoth. My poverty but not my will consents.
Rom. I pay thy poverty and not thy will.
Apoth. Put this in any liquid thing you will
And drink it off, and if you had the strength
Of twenty men, it would dispatch you straight.
Rom. There is thy gold- worse poison to men's souls,
Doing more murther in this loathsome world,
Than these poor compounds that thou mayst not sell.
I sell thee poison; thou hast sold me none.
Farewell. Buy food and get thyself in flesh.
Come, cordial and not poison, go with me
To Juliet's grave; for there must I use thee.
Exeunt.
Scene II.
Verona. Friar Laurence's cell.
Enter Friar John to Friar Laurence.
John. Holy Franciscan friar, brother, ho!
Enter Friar Laurence.
Laur. This same should be the voice of Friar John.
Welcome from Mantua. What says Romeo?
Or, if his mind be writ, give me his letter.
John. Going to find a barefoot brother out,
One of our order, to associate me
Here in this city visiting the sick,
And finding him, the searchers of the town,
Suspecting that we both were in a house
Where the infectious pestilence did reign,
Seal'd up the doors, and would not let us forth,
So that my speed to Mantua there was stay'd.
Laur. Who bare my letter, then, to Romeo?
John. I could not send it- here it is again-
Nor get a messenger to bring it thee,
So fearful were they of infection.
Laur. Unhappy fortune! By my brotherhood,
The letter was not nice, but full of charge,
Of dear import; and the neglecting it
May do much danger. Friar John, go hence,
Get me an iron crow and bring it straight
Unto my cell.
John. Brother, I'll go and bring it thee. Exit.
Laur. Now, must I to the monument alone.
Within this three hours will fair Juliet wake.
She will beshrew me much that Romeo
Hath had no notice of these accidents;
But I will write again to Mantua,
And keep her at my cell till Romeo come-
Poor living corse, clos'd in a dead man's tomb! Exit.
Scene III.
Verona. A churchyard; in it the monument of the Capulets.
Enter Paris and his Page with flowers and [a torch].
Par. Give me thy torch, boy. Hence, and stand aloof.
Yet put it out, for I would not be seen.
Under yond yew tree lay thee all along,
Holding thine ear close to the hollow ground.
So shall no foot upon the churchyard tread
(Being loose, unfirm, with digging up of graves)
But thou shalt hear it. Whistle then to me,
As signal that thou hear'st something approach.
Give me those flowers. Do as I bid thee, go.
Page. [aside] I am almost afraid to stand alone
Here in the churchyard; yet I will adventure. [Retires.]
Par. Sweet flower, with flowers thy bridal bed I strew
(O woe! thy canopy is dust and stones)
Which with sweet water nightly I will dew;
Or, wanting that, with tears distill'd by moans.
The obsequies that I for thee will keep
Nightly shall be to strew, thy grave and weep.
Whistle Boy.
The boy gives warning something doth approach.
What cursed foot wanders this way to-night
To cross my obsequies and true love's rite?
What, with a torch? Muffle me, night, awhile. [Retires.]
Enter Romeo, and Balthasar with a torch, a mattock,
and a crow of iron.
Rom. Give me that mattock and the wrenching iron.
Hold, take this letter. Early in the morning
See thou deliver it to my lord and father.
Give me the light. Upon thy life I charge thee,
Whate'er thou hearest or seest, stand all aloof
And do not interrupt me in my course.
Why I descend into this bed of death
Is partly to behold my lady's face,
But chiefly to take thence from her dead finger
A precious ring- a ring that I must use
In dear employment. Therefore hence, be gone.
But if thou, jealous, dost return to pry
In what I farther shall intend to do,
By heaven, I will tear thee joint by joint
And strew this hungry churchyard with thy limbs.
The time and my intents are savage-wild,
More fierce and more inexorable far
Than empty tigers or the roaring sea.
Bal. I will be gone, sir, and not trouble you.
Rom. So shalt thou show me friendship. Take thou that.
Live, and be prosperous; and farewell, good fellow.
Bal. [aside] For all this same, I'll hide me hereabout.
His looks I fear, and his intents I doubt. [Retires.]
Rom. Thou detestable maw, thou womb of death,
Gorg'd with the dearest morsel of the earth,
Thus I enforce thy rotten jaws to open,
And in despite I'll cram thee with more food.
Romeo opens the tomb.
Par. This is that banish'd haughty Montague
That murd'red my love's cousin- with which grief
It is supposed the fair creature died-
And here is come to do some villanous shame
To the dead bodies. I will apprehend him.
Stop thy unhallowed toil, vile Montague!
Can vengeance be pursu'd further than death?
Condemned villain, I do apprehend thee.
Obey, and go with me; for thou must die.
Rom. I must indeed; and therefore came I hither.
Good gentle youth, tempt not a desp'rate man.
Fly hence and leave me. Think upon these gone;
Let them affright thee. I beseech thee, youth,
But not another sin upon my head
By urging me to fury. O, be gone!
By heaven, I love thee better than myself,
For I come hither arm'd against myself.
Stay not, be gone. Live, and hereafter say
A madman's mercy bid thee run away.
Par. I do defy thy, conjuration
And apprehend thee for a felon here.
Rom. Wilt thou provoke me? Then have at thee, boy!
They fight.
Page. O Lord, they fight! I will go call the watch.
[Exit. Paris falls.]
Par. O, I am slain! If thou be merciful,
Open the tomb, lay me with Juliet. [Dies.]
Rom. In faith, I will. Let me peruse this face.
Mercutio's kinsman, noble County Paris!
What said my man when my betossed soul
Did not attend him as we rode? I think
He told me Paris should have married Juliet.
Said he not so? or did I dream it so?
Or am I mad, hearing him talk of Juliet
To think it was so? O, give me thy hand,
One writ with me in sour misfortune's book!
I'll bury thee in a triumphant grave.
A grave? O, no, a lanthorn, slaught'red youth,
For here lies Juliet, and her beauty makes
This vault a feasting presence full of light.
Death, lie thou there, by a dead man interr'd.
[Lays him in the tomb.]
How oft when men are at the point of death
Have they been merry! which their keepers call
A lightning before death. O, how may I
Call this a lightning? O my love! my wife!
Death, that hath suck'd the honey of thy breath,
Hath had no power yet upon thy beauty.
Thou art not conquer'd. Beauty's ensign yet
Is crimson in thy lips and in thy cheeks,
And death's pale flag is not advanced there.
Tybalt, liest thou there in thy bloody sheet?
O, what more favour can I do to thee
Than with that hand that cut thy youth in twain
To sunder his that was thine enemy?
Forgive me, cousin.' Ah, dear Juliet,
Why art thou yet so fair? Shall I believe
That unsubstantial Death is amorous,
And that the lean abhorred monster keeps
Thee here in dark to be his paramour?
For fear of that I still will stay with thee
And never from this palace of dim night
Depart again. Here, here will I remain
With worms that are thy chambermaids. O, here
Will I set up my everlasting rest
And shake the yoke of inauspicious stars
From this world-wearied flesh. Eyes, look your last!
Arms, take your last embrace! and, lips, O you
The doors of breath, seal with a righteous kiss
A dateless bargain to engrossing death!
Come, bitter conduct; come, unsavoury guide!
Thou desperate pilot, now at once run on
The dashing rocks thy seasick weary bark!
Here's to my love! [Drinks.] O true apothecary!
Thy drugs are quick. Thus with a kiss I die. Falls.
Enter Friar [Laurence], with lanthorn, crow, and spade.
Friar. Saint Francis be my speed! how oft to-night
Have my old feet stumbled at graves! Who's there?
Bal. Here's one, a friend, and one that knows you well.
Friar. Bliss be upon you! Tell me, good my friend,
What torch is yond that vainly lends his light
To grubs and eyeless skulls? As I discern,
It burneth in the Capels' monument.
Bal. It doth so, holy sir; and there's my master,
One that you love.
Friar. Who is it?
Bal. Romeo.
Friar. How long hath he been there?
Bal. Full half an hour.
Friar. Go with me to the vault.
Bal. I dare not, sir.
My master knows not but I am gone hence,
And fearfully did menace me with death
If I did stay to look on his intents.
Friar. Stay then; I'll go alone. Fear comes upon me.
O, much I fear some ill unthrifty thing.
Bal. As I did sleep under this yew tree here,
I dreamt my master and another fought,
And that my master slew him.
Friar. Romeo!
Alack, alack, what blood is this which stains
The stony entrance of this sepulchre?
What mean these masterless and gory swords
To lie discolour'd by this place of peace? [Enters the tomb.]
Romeo! O, pale! Who else? What, Paris too?
And steep'd in blood? Ah, what an unkind hour
Is guilty of this lamentable chance! The lady stirs.
Juliet rises.
Jul. O comfortable friar! where is my lord?
I do remember well where I should be,
And there I am. Where is my Romeo?
Friar. I hear some noise. Lady, come from that nest
Of death, contagion, and unnatural sleep.
A greater power than we can contradict
Hath thwarted our intents. Come, come away.
Thy husband in thy bosom there lies dead;
And Paris too. Come, I'll dispose of thee
Among a sisterhood of holy nuns.
Stay not to question, for the watch is coming.
Come, go, good Juliet. I dare no longer stay.
Jul. Go, get thee hence, for I will not away.
Exit [Friar].
What's here? A cup, clos'd in my true love's hand?
Poison, I see, hath been his timeless end.
O churl! drunk all, and left no friendly drop
To help me after? I will kiss thy lips.
Haply some poison yet doth hang on them
To make me die with a restorative. [Kisses him.]
Thy lips are warm!
Chief Watch. [within] Lead, boy. Which way?
Yea, noise? Then I'll be brief. O happy dagger!
[Snatches Romeo's dagger.]
This is thy sheath; there rest, and let me die.
She stabs herself and falls [on Romeo's body].
Enter [Paris's] Boy and Watch.
Boy. This is the place. There, where the torch doth burn.
Chief Watch. 'the ground is bloody. Search about the churchyard.
Go, some of you; whoe'er you find attach.
[Exeunt some of the Watch.]
Pitiful sight! here lies the County slain;
And Juliet bleeding, warm, and newly dead,
Who here hath lain this two days buried.
Go, tell the Prince; run to the Capulets;
Raise up the Montagues; some others search.
[Exeunt others of the Watch.]
We see the ground whereon these woes do lie,
But the true ground of all these piteous woes
We cannot without circumstance descry.
Enter [some of the Watch,] with Romeo's Man [Balthasar].
2. Watch. Here's Romeo's man. We found him in the churchyard.
Chief Watch. Hold him in safety till the Prince come hither.
Enter Friar [Laurence] and another Watchman.
3. Watch. Here is a friar that trembles, sighs, and weeps.
We took this mattock and this spade from him
As he was coming from this churchyard side.
Chief Watch. A great suspicion! Stay the friar too.
Enter the Prince [and Attendants].
Prince. What misadventure is so early up,
That calls our person from our morning rest?
Enter Capulet and his Wife [with others].
Cap. What should it be, that they so shriek abroad?
Wife. The people in the street cry 'Romeo,'
Some 'Juliet,' and some 'Paris'; and all run,
With open outcry, toward our monument.
Prince. What fear is this which startles in our ears?
Chief Watch. Sovereign, here lies the County Paris slain;
And Romeo dead; and Juliet, dead before,
Warm and new kill'd.
Prince. Search, seek, and know how this foul murder comes.
Chief Watch. Here is a friar, and slaughter'd Romeo's man,
With instruments upon them fit to open
These dead men's tombs.
Cap. O heavens! O wife, look how our daughter bleeds!
This dagger hath mista'en, for, lo, his house
Is empty on the back of Montague,
And it missheathed in my daughter's bosom!
Wife. O me! this sight of death is as a bell
That warns my old age to a sepulchre.
Enter Montague [and others].
Prince. Come, Montague; for thou art early up
To see thy son and heir more early down.
Mon. Alas, my liege, my wife is dead to-night!
Grief of my son's exile hath stopp'd her breath.
What further woe conspires against mine age?
Prince. Look, and thou shalt see.
Mon. O thou untaught! what manners is in this,
To press before thy father to a grave?
Prince. Seal up the mouth of outrage for a while,
Till we can clear these ambiguities
And know their spring, their head, their true descent;
And then will I be general of your woes
And lead you even to death. Meantime forbear,
And let mischance be slave to patience.
Bring forth the parties of suspicion.
Friar. I am the greatest, able to do least,
Yet most suspected, as the time and place
Doth make against me, of this direful murther;
And here I stand, both to impeach and purge
Myself condemned and myself excus'd.
Prince. Then say it once what thou dost know in this.
Friar. I will be brief, for my short date of breath
Is not so long as is a tedious tale.
Romeo, there dead, was husband to that Juliet;
And she, there dead, that Romeo's faithful wife.
I married them; and their stol'n marriage day
Was Tybalt's doomsday, whose untimely death
Banish'd the new-made bridegroom from this city;
For whom, and not for Tybalt, Juliet pin'd.
You, to remove that siege of grief from her,
Betroth'd and would have married her perforce
To County Paris. Then comes she to me
And with wild looks bid me devise some mean
To rid her from this second marriage,
Or in my cell there would she kill herself.
Then gave I her (so tutored by my art)
A sleeping potion; which so took effect
As I intended, for it wrought on her
The form of death. Meantime I writ to Romeo
That he should hither come as this dire night
To help to take her from her borrowed grave,
Being the time the potion's force should cease.
But he which bore my letter, Friar John,
Was stay'd by accident, and yesternight
Return'd my letter back. Then all alone
At the prefixed hour of her waking
Came I to take her from her kindred's vault;
Meaning to keep her closely at my cell
Till I conveniently could send to Romeo.
But when I came, some minute ere the time
Of her awaking, here untimely lay
The noble Paris and true Romeo dead.
She wakes; and I entreated her come forth
And bear this work of heaven with patience;
But then a noise did scare me from the tomb,
And she, too desperate, would not go with me,
But, as it seems, did violence on herself.
All this I know, and to the marriage
Her nurse is privy; and if aught in this
Miscarried by my fault, let my old life
Be sacrific'd, some hour before his time,
Unto the rigour of severest law.
Prince. We still have known thee for a holy man.
Where's Romeo's man? What can he say in this?
Bal. I brought my master news of Juliet's death;
And then in post he came from Mantua
To this same place, to this same monument.
This letter he early bid me give his father,
And threat'ned me with death, going in the vault,
If I departed not and left him there.
Prince. Give me the letter. I will look on it.
Where is the County's page that rais'd the watch?
Sirrah, what made your master in this place?
Boy. He came with flowers to strew his lady's grave;
And bid me stand aloof, and so I did.
Anon comes one with light to ope the tomb;
And by-and-by my master drew on him;
And then I ran away to call the watch.
Prince. This letter doth make good the friar's words,
Their course of love, the tidings of her death;
And here he writes that he did buy a poison
Of a poor pothecary, and therewithal
Came to this vault to die, and lie with Juliet.
Where be these enemies? Capulet, Montage,
See what a scourge is laid upon your hate,
That heaven finds means to kill your joys with love!
And I, for winking at you, discords too,
Have lost a brace of kinsmen. All are punish'd.
Cap. O brother Montague, give me thy hand.
This is my daughter's jointure, for no more
Can I demand.
Mon. But I can give thee more;
For I will raise her Statue in pure gold,
That whiles Verona by that name is known,
There shall no figure at such rate be set
As that of true and faithful Juliet.
Cap. As rich shall Romeo's by his lady's lie-
Poor sacrifices of our enmity!
Prince. A glooming peace this morning with it brings.
The sun for sorrow will not show his head.
Go hence, to have more talk of these sad things;
Some shall be pardon'd, and some punished;
For never was a story of more woe
Than this of Juliet and her Romeo.
Exeunt omnes.
THE END
<<THIS ELECTRONIC VERSION OF THE COMPLETE WORKS OF WILLIAM
SHAKESPEARE IS COPYRIGHT 1990-1993 BY WORLD LIBRARY, INC., AND IS
PROVIDED BY PROJECT GUTENBERG ETEXT OF ILLINOIS BENEDICTINE COLLEGE
WITH PERMISSION. ELECTRONIC AND MACHINE READABLE COPIES MAY BE
DISTRIBUTED SO LONG AS SUCH COPIES (1) ARE FOR YOUR OR OTHERS
PERSONAL USE ONLY, AND (2) ARE NOT DISTRIBUTED OR USED
COMMERCIALLY. PROHIBITED COMMERCIAL DISTRIBUTION INCLUDES BY ANY
SERVICE THAT CHARGES FOR DOWNLOAD TIME OR FOR MEMBERSHIP.>>
1594
THE TAMING OF THE SHREW
by William Shakespeare
Dramatis Personae
Persons in the Induction
A LORD
CHRISTOPHER SLY, a tinker
HOSTESS
PAGE
PLAYERS
HUNTSMEN
SERVANTS
BAPTISTA MINOLA, a gentleman of Padua
VINCENTIO, a Merchant of Pisa
LUCENTIO, son to Vincentio, in love with Bianca
PETRUCHIO, a gentleman of Verona, a suitor to Katherina
Suitors to Bianca
GREMIO
HORTENSIO
Servants to Lucentio
TRANIO
BIONDELLO
Servants to Petruchio
GRUMIO
CURTIS
A PEDANT
Daughters to Baptista
KATHERINA, the shrew
BIANCA
A WIDOW
Tailor, Haberdasher, and Servants attending on Baptista and
Petruchio
SCENE:
Padua, and PETRUCHIO'S house in the country
SC_1
INDUCTION. SCENE I.
Before an alehouse on a heath
Enter HOSTESS and SLY
SLY. I'll pheeze you, in faith.
HOSTESS. A pair of stocks, you rogue!
SLY. Y'are a baggage; the Slys are no rogues. Look in the
chronicles: we came in with Richard Conqueror. Therefore, paucas
pallabris; let the world slide. Sessa!
HOSTESS. You will not pay for the glasses you have burst?
SLY. No, not a denier. Go by, Saint Jeronimy, go to thy cold bed
and warm thee.
HOSTESS. I know my remedy; I must go fetch the third-borough.
Exit
SLY. Third, or fourth, or fifth borough, I'll answer him by law.
I'll not budge an inch, boy; let him come, and kindly.
[Falls asleep]
Wind horns. Enter a LORD from hunting, with his train
LORD. Huntsman, I charge thee, tender well my hounds;
Brach Merriman, the poor cur, is emboss'd;
And couple Clowder with the deep-mouth'd brach.
Saw'st thou not, boy, how Silver made it good
At the hedge corner, in the coldest fault?
I would not lose the dog for twenty pound.
FIRST HUNTSMAN. Why, Belman is as good as he, my lord;
He cried upon it at the merest loss,
And twice to-day pick'd out the dullest scent;
Trust me, I take him for the better dog.
LORD. Thou art a fool; if Echo were as fleet,
I would esteem him worth a dozen such.
But sup them well, and look unto them all;
To-morrow I intend to hunt again.
FIRST HUNTSMAN. I will, my lord.
LORD. What's here? One dead, or drunk?
See, doth he breathe?
SECOND HUNTSMAN. He breathes, my lord. Were he not warm'd with ale,
This were a bed but cold to sleep so soundly.
LORD. O monstrous beast, how like a swine he lies!
Grim death, how foul and loathsome is thine image!
Sirs, I will practise on this drunken man.
What think you, if he were convey'd to bed,
Wrapp'd in sweet clothes, rings put upon his fingers,
A most delicious banquet by his bed,
And brave attendants near him when he wakes,
Would not the beggar then forget himself?
FIRST HUNTSMAN. Believe me, lord, I think he cannot choose.
SECOND HUNTSMAN. It would seem strange unto him when he wak'd.
LORD. Even as a flatt'ring dream or worthless fancy.
Then take him up, and manage well the jest:
Carry him gently to my fairest chamber,
And hang it round with all my wanton pictures;
Balm his foul head in warm distilled waters,
And burn sweet wood to make the lodging sweet;
Procure me music ready when he wakes,
To make a dulcet and a heavenly sound;
And if he chance to speak, be ready straight,
And with a low submissive reverence
Say 'What is it your honour will command?'
Let one attend him with a silver basin
Full of rose-water and bestrew'd with flowers;
Another bear the ewer, the third a diaper,
And say 'Will't please your lordship cool your hands?'
Some one be ready with a costly suit,
And ask him what apparel he will wear;
Another tell him of his hounds and horse,
And that his lady mourns at his disease;
Persuade him that he hath been lunatic,
And, when he says he is, say that he dreams,
For he is nothing but a mighty lord.
This do, and do it kindly, gentle sirs;
It will be pastime passing excellent,
If it be husbanded with modesty.
"""
LETTERS = [w for w in PLAY]
WORDS = PLAY.split(' ')
@moreati
Copy link

moreati commented Jul 17, 2019

For anyone else wondering, after some syntax fixes

$ python2.7 benchmark.py 
defaultdict letters: 1.49439883232
defaultdict words: 0.689834117889
setdefault letters: 3.59278202057
setdefault words: 1.06224393845
Counter letters: 5.15295696259
Counter words: 1.43742799759
26727 letters and 6691 words

$ python3.6 benchmark.py 
defaultdict letters: 2.0653242469998077
defaultdict words: 0.8429669320030371
setdefault letters: 4.329114729000139
setdefault words: 1.204490740012261
Counter letters: 1.0499275939946529
Counter words: 0.3512040450004861
26727 letters and 6691 words

$ python3.7 benchmark.py 
defaultdict letters: 1.9213471849943744
defaultdict words: 0.7896472610009369
setdefault letters: 3.328444508006214
setdefault words: 0.9833477599895559
Counter letters: 1.064254210999934
Counter words: 0.3557306449947646
26727 letters and 6691 words

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment